Capture and visualize metrics using Datadog

Component: Metrics
NuGet Package NServiceBus (7.x)

Introduction

This sample demonstrates how to capture, store, and visualize NServiceBus metrics in Datadog, a monitoring solution for storing application performance data.

This sample reports the following metrics to Datadog:

  • Fetched messages per second
  • Failed messages per second
  • Successful messages per second
  • Critical time in seconds
  • Processing time seconds
  • Retries

For a detailed explanation of these metrics refer to the metrics captured section in the metrics documentation section.

Prerequisites

To run this sample, create a Datadog account, then download and run the Datadog agent. See the Introduction to Datadog guide for information on how to get started with Datadog metrics.

Code overview

The sample simulates messages load with a random 10% failure rate using the LoadSimulator class: LoadSimulator

Capturing metric values

Setup Datadog client. Let' s assume the Datadog agent runs on default address and port.

var dogstatsdConfig = new StatsdConfig
{
    StatsdServerName = "127.0.0.1",
    StatsdPort = 8125,
}; //Datadog agent default address, port

DogStatsd.Configure(dogstatsdConfig);

Custom observers need to be registered for the metric probes provided via NServiceBus.Metrics. This is configured in the DatadogFeature. The registered observers convert NServiceBus.Metric Signals to Datadog Count and NServiceBus.Metric Durations to Datadog Timer

_metricsOptions.RegisterObservers(register: probeContext =>
    {
        foreach (var duration in probeContext.Durations)
        {
            if (!_nameMapping.ContainsKey(duration.Name))
            {
                continue;
            }
            duration.Register((ref DurationEvent @event) =>
            {
                var statName = ComposeStatName(duration.Name, @event.MessageType);
                DogStatsd.Timer(statName, @event.Duration.TotalMilliseconds);
            });
        }

        foreach (var signal in probeContext.Signals)
        {
            if (!_nameMapping.ContainsKey(signal.Name))
            {
                continue;
            }
            signal.Register((ref SignalEvent @event) =>
            {
                var statName = ComposeStatName(signal.Name, @event.MessageType);
                DogStatsd.Increment(statName);
            });
        }
    });

Dashboard

metrics summary dashboard

Create

Dashboards can be created by using Datadog.


Last modified