Consume raw data from Metrics

Component: Metrics
NuGet Package NServiceBus.Metrics (2.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 in a few different ways.

To any external storage

Custom observers might be registered to access every value reported by probes.

metrics.RegisterObservers(
    register: context =>
    {
        foreach (var duration in context.Durations)
        {
            duration.Register(
                observer: (ref DurationEvent @event) =>
                {
                    Console.WriteLine($"Duration: '{duration.Name}'. Value: '{@event.Duration}'");
                });
        }
        foreach (var signal in context.Signals)
        {
            signal.Register(
                observer: (ref SignalEvent @event) =>
                {
                    Console.WriteLine($"Signal: '{signal.Name}'. Type: '{@event.MessageType}'");
                });
        }
    });

Samples


Last modified