【问题标题】:How can I add a performance counter to a category i have already created如何将性能计数器添加到我已经创建的类别
【发布时间】:2010-10-31 18:50:44
【问题描述】:

我创建了如下所示的 PerformanceCounterCategory

var category = PerformanceCounterCategory.Create("MyCat", "Cat Help",
    PerformanceCounterCategoryType.SingleInstance, "MyCounter", "Counter Help);

如何向类别添加新计数器以监控其他项目?
我找不到它的 api。

【问题讨论】:

标签: c# .net performancecounter


【解决方案1】:
PerformanceCounter lCounter = new PerformanceCounter(Category, CounterName, 
                                                     false);
lCounter.MachineName = ".";

【讨论】:

  • 谢谢,我会在早上启动工作笔记本电脑时尝试一下
  • 首先使用所有计数器及其类型设置您的 CounterCategory,如下所示 var lCounters = new CounterCreationDataCollection(); lCounters.Add(new CounterCreationData(lCounterName, lounterHelp, lCounterType)); PerformanceCounterCategory.Create(pCategory, lCategoryHelp, PerformanceCounterCategoryType.SingleInstance, lCounters);然后当你想要一个计数器的实例时,检查类别/计数器是否存在,然后执行以下操作.... var lCounter = new PerformanceCounter(pCategory, pCounterName, false); lCounter.MachineName = ".";希望这会有所帮助。
【解决方案2】:

我不久前对此进行了研究,似乎无法将计数器添加到现有类别中,您必须这样做才能通过添加新计数器重新创建相同的类别。

【讨论】:

  • +1 使用PerformanceCounterCategory.Delete,后跟PerformanceCounterCategory.Create
猜你喜欢
  • 2020-10-16
  • 1970-01-01
  • 2011-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-27
  • 1970-01-01
相关资源
最近更新 更多