Windows Performance Counters

NuGet Package NServiceBus (3.x)
Standard support for version 3.x of NServiceBus has expired. For more information see our Support Policy.

When a system is broken down into multiple processes, each with its own queue, it allows identifying which process is the bottleneck by examining how many messages (on average) are in each queue. The only issue is that without knowing the rate of messages coming into each queue, and the rate at which messages are being processed from each queue, it is not possible to know how long messages are waiting in each queue, which is the primary indicator of a bottleneck.

Despite the many performance counters Microsoft provides for MSMQ (including messages in queues, machine-wide incoming and outgoing messages per second, and the total messages in all queues), there is no built-in performance counter for the time it takes a message to get through each queue.

NServiceBus includes several performance counters. They are installed in the NServiceBus category.

Since all performance counters in Windows are exposed via Windows Management Instrumentation (WMI), it is very straightforward to pull this information into the existing monitoring infrastructure.

The NServiceBus performance counters only indicate activity on the logical endpoint queue and endpoint instance specific queue.

Critical Time

Counter Name: Critical Time

Added in: Version 3

Critical Time is the time from a message being sent until successfully processed. This metric is useful for monitoring a message's service-level agreement. For example: "All orders should be processed within 30 seconds". Define an SLA for each endpoint and use the CriticalTime counter to ensure it is adhered to.


This counter can be enabled using the following code:

// in this version there was no granular control over individual counters

In the NServiceBus host this counter is enabled by default.

SLA violation countdown

Counter Name: SLA violation countdown

Added in: Version 3

Acts as an early warning system to inform on the number of seconds left until the SLA for the endpoint is breached. The counter shows the number of seconds left until the configured SLA value for a given endpoint is breached. The higher the value the less risk there is to breach the SLA for a given endpoint.


This counter can be enabled using the the following code:

// in this version there was no granular control over individual counters

See also Performance Counters in the NServiceBus Host.

Installing Counters

The NServiceBus performance counters can be installed using the NServiceBus PowerShell tools.

Import-Module NServiceBus.PowerShell

To list the installed counters use

Get-Counter -ListSet NServiceBus | Select-Object -ExpandProperty Counter
After installing the performance counters, all endpoints must be restarted in order to start collecting the new data.

Performance Monitor Users local security group

When running installers, the service account will be automatically added to the local Performance Monitor Users group if executed with elevated privileges.


If the endpoint instance throws one of the following exceptions at startup, then the performance counters need to be reinstalled

  • InvalidOperationException: The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly.
  • InvalidOperationException: NServiceBus performance counter for 'Critical Time' is not set up correctly.

Corrupted Counters

Corrupted performance counters can cause the endpoint to either hang completely during startup or fail with the following error:

NServiceBus performance counter for '{counterName}' is not set up correctly

Should this happen, try rebuilding the performance counter library using the following steps:

  1. Open an elevated command prompt
  2. Execute the following command to rebuild the performance counter library: lodctr /r

More information


Related Articles

  • Auditing Messages
    Configure where to send messages and it provides built-in message auditing for every endpoint.
  • Management using PowerShell
    Install the infrastructure for NServiceBus on servers using PowerShell.
  • Operations
    Operations Table of Contents.
  • Recoverability
    Explains how exceptions are handled, and actions retried, during message processing.

Last modified