For the complete documentation index, see llms.txt. This section of documentation is indexed by https://docs.particular.net/monitoring/llms.txt. Here is the markdown version of this page. Markdown versions of documentation pages are available by appending .md to the page URL. Directory URLs use index.md.

Consume raw data from Metrics

Component:
Metrics
NuGet Package:
NServiceBus.Metrics 5.x
Target Version:
NServiceBus 9.x

When Performance Counters reporting and ServiceControl reporting are not enough, it's possible to consume raw metrics data by directly attaching them 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);
                });
        }
    });

List of Samples

Related Articles