“类别不存在."为MSMQ队列创建性能计数器 [英] "Category does not exist." Creating performance counter for MSMQ Queue

查看:132
本文介绍了“类别不存在."为MSMQ队列创建性能计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试:

using System.Diagnostics;

// ...
var queueCounter = new PerformanceCounter(
    "MSMQ Queue", 
    "Messages in Queue", 
    @"machinename\private$\testqueue2");

Console.WriteLine( "Queue contains {0} messages", 
    queueCounter.NextValue().ToString());

来自此职位的人: 有没有办法检查MSMQ队列中有多少条消息?

这里提到了相同的错误,但是在使用PerformanceCounter时没有解决方法.

There is mention of this same error, but no resolution when using PerformanceCounter.

我也在这里提到了: 性能计数器-System.InvalidOperationException:类别不存在

I also found mention here: Performance Counter - System.InvalidOperationException: Category does not exist

但是,该线程从这个确切的主题开始,但是在回答有关如何处理该错误的初始问题之前,走了另一个方向.基本上,我不需要知道每秒的记录,只需要知道何时开始备份队列.

However, this thread started on this exact topic, but went another direction before answering the initial question on what to do about the error. Basically I don't need to know records per second, I only need to know when a queue starts getting backed up.

什么原因导致此错误?我尝试过指向私有和公共队列以及指向其中包含消息的队列.

What causes this error? I have tried pointing to private and public queue's as well as pointing to queues that had messages in them.

我在perfmon中添加了计数器,以确保服务器路径和队列名称正确.

I have added the counter in perfmon to ensure I have the server path and queue name correct.

推荐答案

好吧……知道了.队列名称本身不包括它们在其上运行的machineName的完全限定名称.我通过使用PerformanceCounterCategory.GetInstanceNames()发现了这一点.这为您提供了正确的队列名称.解决方法是使用PerformanceCounter的最后一个构造函数进行更新,该构造函数可让您指定计算机名称.我指定的队列名称是计算机名称,但是计算机名称是完全限定的:

Ok... figured it out. The queue names themselves did not include the fully qualified name of the machineName they were running on. I discovered this by using the PerformanceCounterCategory.GetInstanceNames(). This gives you the correct name of the queue. The fix was to new up using the last constructor of PerformanceCounter that lets you specify the machine name. The queue name I specify is the machine name, but the machine name is fully qualified:

new PerformanceCounter("MSMQ Queue", "Messages in Queue", @"<machine name>\private$\dispatch", @"<fully qualified machine name>"))

这篇关于“类别不存在."为MSMQ队列创建性能计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆