"Category does not exist." Create a performance counter for the MSMQ queue
I am trying to do this:
using System.Diagnostics;
// ...
var queueCounter = new PerformanceCounter(
"MSMQ Queue",
"Messages in Queue",
@"machinename\private$\testqueue2");
Console.WriteLine( "Queue contains {0} messages",
queueCounter.NextValue().ToString());
Which of this post: Is there a way to check how many messages are in the MSMQ queue?
The same error is mentioned here, but there is no permission when using PerformanceCounter.
I also found a mention here: Performance Counter - System.InvalidOperationException: Category does not exist
However, this thread started exactly on this topic, but went in another direction before answering the original question of what to do with the error. Basically, I don't need to know the records per second, I only need to know when the queue starts backing up.
What is causing this error? I tried to point to a private and public queue, and also point to the queues that contained messages.
Edit: I added a counter to perfmon to make sure the server path and queue name is correct.
source to share
Ok ... figured it out. The queue names themselves did not contain the full name of the name of the machine on which they were run. I discovered this using PerformanceCounterCategory.GetInstanceNames (). This gives the correct queue name. The fix was related to the new use of the latest PerformanceCounter constructor, which allows you to specify a machine name. The queue name I am specifying is the machine name, but the fully qualified machine name:
new PerformanceCounter("MSMQ Queue", "Messages in Queue", @"<machine name>\private$\dispatch", @"<fully qualified machine name>"))
source to share