Windows Performance Counters

NuGet Package NServiceBus (6.x)
Standard support for version 6.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. However, it is not possible to know how long messages are waiting in each queue - which is the primary indicator of a bottleneck - without knowing the rate of messages coming into each queue, and the rate at which messages are being processed from each queue.

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 to address this. 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. Any activity on the satellites is not visible.

Critical Time

Counter Name: Critical Time

Added in: Version 3

Critical Time is the time taken from when a message is sent until it has been 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 the NServiceBus host this counter is enabled by default.

Versions 6 and above: The value recorded in the TimeSent header is the time when the call to send the message is executed, not the time when the message was dispatched to the transport infrastructure. Since the outgoing messages in handlers are sent in batches, the dispatch may happen later than the time recorded in the TimeSent header. For operations outside of handlers the recorded sent time is accurate.

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:


See also Performance Counters in the NServiceBus Host.

Successful Message Processing Rate

Counter Name: # of msgs successfully processed / sec

Added in: Version 4

The current number of messages successfully processed by the transport per second.


Enabled by default and will only write to the counter if it exists.

Queue Message Receive Rate

Counter Name: # of msgs pulled from the input queue / sec

Added in: Version 4

The current number of messages pulled from the input queue by the transport per second.


Enabled by default and will only write to the counter if it exists.

Failed Message Processing Rate

Counter Name: # of msgs failures / sec

Added in: Version 4

The current number of messages per second that the transport failed to process.


Enabled by default and will only write to the counter if it exists.

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

Send-only endpoints are currently not supported since they don't receive messages.


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