When Performance Counters reporting and ServiceControl reporting is not enough, it's possible to consume raw metrics data by directly attaching to the public API provided by the package. First, the Metrics themselves need to be enabled. Then, a custom reporter can be attached to send data to any collector e.g. Service Control, Azure Application Insights, etc.
Enabling NServiceBus.Metrics
var metrics = endpointConfiguration.EnableMetrics();
Reporting metrics data
Metrics can be reported in a few different ways.
To any external storage
Custom observers might be registered to access every value reported by probes.
var durationsLog = LogManager.GetLogger("Durations");
var signalsLog = LogManager.GetLogger("Signals");
metrics.RegisterObservers(
register: context =>
{
foreach (var duration in context.Durations)
{
duration.Register(
observer: (ref DurationEvent @event) =>
{
durationsLog.DebugFormat("{0} = {1}", duration.Name, @event.Duration);
});
}
foreach (var signal in context.Signals)
{
signal.Register(
observer: (ref SignalEvent @event) =>
{
signalsLog.DebugFormat("{0} = {1}", signal.Name, @event.MessageType);
});
}
});