为什么我没有`_Total`性能计数器实例?

时间:2014-08-21 03:45:45

标签: c# windows performancecounter

我正在使用以下注册码创建一个多实例性能计数器,但似乎没有_Total实例 - 即使我有多个活动实例。我需要做些什么来获得总数?

注册码:

var slc = new CounterCreationDataCollection();
slc.Add(new CounterCreationData()
{
    CounterName = "Channels Open",
    CounterType = PerformanceCounterType.NumberOfItems32,
    CounterHelp = "Number of channels that have not been cleaned up."
});
PerformanceCounterCategory.Create("Frob", "Monitors the frob", 
    PerformanceCounterCategoryType.MultiInstance, slc);

报告代码:

var channelName = "Widget 6";
var pcOpen = new PerformanceCounter("Frob", "Channels Open", channelName, false);

// elsewhere
pcOpen.Increment();

// followed by
pcOpen.Decrement();

产地:

Image showing my counter without a total

1 个答案:

答案 0 :(得分:1)

我认为_Total计数器只是另一个手动汇总总计的实例。它具有前导_的原因是它在< <All instances>之前按字母顺序排列,它是一个&#34; meta&#34;计数器。

var pc5Name = "Widget 5";
var pc6Name = "Widget 6";
var pc5 = new PerformanceCounter("Frob", "Channels Open", pc5Name, false);
var pc6 = new PerformanceCounter("Frob", "Channels Open", pc6Name, false);
var pcTotal = new PerformanceCounter("Frob", "Channels Open", "_Total", false);

// elsewhere
pc5.Increment();
pcTotal.Increment()

// more elsewhere
pc6.Increment();
pcTotal.Increment()

// followed by
pc5.Decrement();
pcTotal.Decrement();