The NServiceBus. component enables sending monitoring data gathered with NServiceBus. to a ServiceControl. service.
This plugin can be enabled and configured with the ServicePlatform Connector plugin.
The metrics feature can't be used on send-only endpoints
When using the MSMQ transport, the additional NServiceBus. package is required to report queue length, which ServiceControl cannot measure for MSMQ itself. All other metrics are reported without it.
Configuration
To install the plugin in an endpoint, reference the NServiceBus.Metrics.ServiceControl NuGet package, which allows collection and propagation of metrics to ServiceControl.
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");
Service Control Metrics Address
The default instance name is particular. which is also used as the input queue for ServiceControl monitoring.
Interval
Specifies the maximum delay between sending metrics report messages.
The metrics plugin buffers measurements and sends a metric report message as soon as the buffer is half full, without waiting for the interval to elapse. When an endpoint instance is idle the plugin will still send a report at this interval so that ServiceControl monitoring knows that the instance is still running. When the endpoint is under load, the time between metric messages will be much shorter as the buffer fills faster.
The size of this buffer is fixed and cannot be adjusted. The size chosen is compatible with the maximum message size limits of all supported transports.
The recommended value is between 10 and 60 seconds.
- Smaller values result in ServiceControl monitoring view to be updated faster, especially on the 1-minute timescale
- 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 6000 messages per minute (500 × 12), which is 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
Overrides the value ServiceControl monitoring uses to identify this endpoint instance, in place of $. and $..
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 plugin will use these values to identify the monitored endpoint instances in the user interface.
Make sure that the InstanceId value is unique, human-readable, and stable between restarts. ServiceControl monitoring identifies instances by this value, so a value that changes on restart appears as a new instance.
A human-readable value is 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);