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 to a number of different locations. Each location is updated on a separate interval.
To NServiceBus log
Metrics data can be written to the NServiceBus Log.
metrics.EnableLogTracing(interval: TimeSpan.FromMinutes(5));
DEBUG
log level. The API allows this parameter to be customized.metrics.EnableLogTracing(
interval: TimeSpan.FromMinutes(5),
logLevel: LogLevel.Info);
To trace log
Metrics data can be written to System.Diagnostics.Trace.
metrics.EnableMetricTracing(interval: TimeSpan.FromSeconds(5));
To custom function
Metrics data can be consumed by a custom function.
metrics.EnableCustomReport(
func: data =>
{
// process metrics
return Task.CompletedTask;
},
interval: TimeSpan.FromSeconds(5));
To Windows Performance Counters
Some of the data captured by the NServiceBus.Metrics component can be forwarded to Windows Performance Counters. See Performance Counters for more information.