安装的性能计数器总计实例 [英] Installing a Total instance for Performance Counters

查看:155
本文介绍了安装的性能计数器总计实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VS 2005,C#2.0,.NET 2.0 / 3.0,Win2003的

VS 2005, C# 2.0, .NET 2.0/3.0, Win2003

我想安装一组性能计数器为多实例。我注意到,一些系统性能计数器类别管理,保持了即使没有其他情况下活着。 ASP.NET应用程序2.0.50727就是一个例子。

I'm trying to install a set of performance counters for a MultiInstance. I noticed that some system performance counter categories manage to keep a "total" alive even when there are no other instances. ASP.NET Apps 2.0.50727 is an example.

所以,我一直在试图复制此。我创建了一个安装程序类下面的程序,然后我添加到自定义操作的安装项目。

So I've been trying to duplicate this. I created the following routine in an Installer class which I then add to a Custom Action in a setup project.

public override void Install(System.Collections.IDictionary stateSaver)
{
    //Debugger.Break();
    CounterCreationData data = new CounterCreationData("ZCounter", "ZCtrHelp", PerformanceCounterType.NumberOfItems32);
    PerformanceCounterCategory.Create("ZCategory", "ZCatHelp", PerformanceCounterCategoryType.MultiInstance, new CounterCreationDataCollection(new CounterCreationData[] { data }));
    PerformanceCounter counter = new PerformanceCounter();
    counter.CategoryName = "ZCategory";
    counter.CounterName = "ZCounter";
    counter.InstanceName = "ZTotal";
    counter.InstanceLifetime = PerformanceCounterInstanceLifetime.Global;
    counter.ReadOnly = false;
    counter.RawValue = 0;
    base.Install(stateSaver);
}

如果我取消注释 Debugger.Break()线,并逐步完成,我可以看到柜台实际上是与正确的实例名称创建,和Visual Studio服务器资源管理器显示随着InstanceLifetime设置为全局实例。我不叫,在安装程序的RemoveInstance()方法。

If I uncomment the Debugger.Break() line, and step through, I can see the counter is actually created with the right instance name, and Visual Studio Server Explorer shows the instance along with the InstanceLifetime set to Global. I do not call the RemoveInstance() method in the setup program.

不过,安装程序完成后,几秒钟后,该实例从性能监视器,并从VS服务器资源管理器中消失。我如何坚持下去?或者,可以吗?

Nevertheless, a few seconds after the setup program completes, that instance disappears from the Performance Monitor and from the VS Server Explorer. How do I make it stick? Or can I?

推荐答案

有些code,必须积极维护计数器。在所有的情况下,你能想到的,如ASP.Net,有保持计数,最多的服务。

Some code has to be actively maintaining the counter. In all the instances you can think of, such as ASP.Net, there is a service keeping the counter up.

由于你不快乐与具有_Total实例您的应用程序的一些实例在运行时只活跃,您必须写一些code表示将保持性能计数器之外的应用。没有什么神奇的。

As you aren't happy with having a _Total instance only active while some instance of your app is running, you have to write some code that will maintain the performance counter outside of your application. There's no magic.

您可以写一个小服务,只要您的监控需求。这将保持_Total计数器。你需要决定一个更新方案。最简单的是让你的应用程序的每个实例都更新这两个实例(自己的和_Total)。

You can write a small service that does your monitoring needs. This will maintain the _Total counter. You need to decide on an update regimen. The easiest is to have every instance of your app update both instances (their own and _Total).

的背景性能计数器位 - 最主要的是要明白的是,有通常是通过联锁操作更新进程间共享内存区域共享。像性能监视器的工具(或任何其它应用程序)结束了连接到共享存储区域来获取电流值。因此,一些过程必须有共享内存区域打开和拥有。因此,为什么你需要code运行。性能监视器不为您创建_Total实例(它也有专柜,允许均线和价格的一些pretty的令人费解的组合,而不是一笔创建摘要实例)。

A bit of background on performance counters - the main thing to understand is that there is typically a shared memory region shared between processes that is updated via interlocked operations. A tool like PerfMon (or any other app) ends up connecting to the shared memory region to get the current values. So some process has to have that shared memory region opened and owned. Thus why you need code running. PerfMon is not creating the _Total instance for you (it does have some pretty convoluted combinations of counters allowing for averages and rates, but not a sum to create a summary instance).

这篇关于安装的性能计数器总计实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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