Consume raw data from Metrics

Component: Metrics
Target Version: NServiceBus 6.x
Standard support for version 6.x of NServiceBus has expired. For more information see our Support Policy.

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));
By default metrics will be written to the log at the DEBUG log level. The API allows this parameter to be customized.
    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.

    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.


Last modified