Consume raw data from Metrics

Component: Metrics
NuGet Package NServiceBus.Metrics (1.x)
Target NServiceBus Version: 6.x

When Performance Counters reporting and Service Control reporting is not enough, it's possible to consume raw metrics data, 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.
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.

Samples


Last modified