Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Samples

Send Metrics data to ServiceControl

NuGet Package: NServiceBus.Metrics.ServiceControl (5.x)
Target Version: NServiceBus 9.x

The NServiceBus.Metrics.ServiceControl component enables sending monitoring data gathered with NServiceBus.Metrics to a ServiceControl.Monitoring service.

Configuration

After adding the package to the project, metrics are sent to ServiceControl once enabled.

It can be enabled via:

const string SERVICE_CONTROL_METRICS_ADDRESS = "particular.monitoring";

var metrics = endpointConfiguration.EnableMetrics();

metrics.SendMetricDataToServiceControl(
    serviceControlMetricsAddress: SERVICE_CONTROL_METRICS_ADDRESS,
    interval: TimeSpan.FromMinutes(1),
    instanceId: "INSTANCE_ID_OPTIONAL");
The metrics feature can't be used on send-only endpoints

Service Control Metrics Address

The default instance name is particular.monitoring which is also used as the input queue for ServiceControl monitoring.

Interval

Specifies the maximum delay between sending metrics report messages.

The metrics plugin has a buffer and when that overflows a metric report message is sent and the buffer is cleared. When an endpoint instance is idle it will send metrics report messages at this interval to indicate it is idle. When the endpoint is under load the interval between metric messages will be much shorter as this buffer fills faster.

The size of this buffer is fixed and cannot be adjusted. The size value chosen that is compatible with the maximum message size limits of all supported transports.

The recommended value is between 10 and 60 seconds.

  1. Smaller values result in ServiceControl monitoring view to be updated faster, especially on the 1-minute timescale
  2. Larger values result in less frequent ServiceControl monitoring view updates only when an instance is not under heavy load. This isn't affecting the monitoring view with 10-minutes or larger timescales

It is recommended to use higher values for systems that can have many endpoint instances or use a transport that might be affected by rate limiting (often cloud-based).

Example:

If the system has 500 instances and the interval is set to 5 seconds an idle system will send on average 6.000 metric messages per minute (500 * 6) / 100 per second.

Time To Be Received

By default, messages sent to the monitoring instance of ServiceControl have Time To Be Received set to 7 days. This value can be overridden when needed using following API:

metrics.SetServiceControlMetricsMessageTTBR(TimeSpan.FromHours(1));

Instance ID

An override for $.diagnostics.hostid and $.diagnostics.hostdisplayname.

It is recommended to override the host id and host display name via NServiceBus core and to use the API without the InstanceId argument. By default, the monitoring plug-in will use these values to identify the monitored endpoint instances in the user-interface.

Make sure that the InstanceId value is unique and human readable.

A human readable value is being passed in the following example:

const string SERVICE_CONTROL_METRICS_ADDRESS = "particular.monitoring";

var endpointName = "MyEndpoint";
var machineName = $"{Dns.GetHostName()}.{IPGlobalProperties.GetIPGlobalProperties().DomainName}";
var instanceIdentifier = $"{endpointName}@{machineName}";

var metrics = endpointConfiguration.EnableMetrics();

metrics.SendMetricDataToServiceControl(
    serviceControlMetricsAddress: SERVICE_CONTROL_METRICS_ADDRESS,
    interval: TimeSpan.FromMinutes(1),
    instanceId: instanceIdentifier);
It is not required to add a process identification. The InstanceId is not required to be physically identifying the running instance uniquely. The plugin uses its own internal unique session identifier for this.

Samples