通过 PerformanceCounterCategory 添加计数器
你好 使用 PerformanceCounterCategory.Create 创建性能计数器类别后,是否可以向该类别添加额外的计数器? 或者我必须先删除它并重新创建它?
谢谢 萨尔
Hi
Once I create a Performance Counter Category using PerformanceCounterCategory.Create, is it possible to add an additional counter to that category?
Or do I have to first delete it and re-create it?
Thanks
Saar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在我的所有代码中,我总是要么创建所有计数器,要么删除它们,但绝不会修改它们以仅添加一个。它通常不是要做的事情,因为性能计数器通常作为应用程序安装的一部分安装一次,或者在应用程序删除后删除。同样,我通常有一个安装程序类,因此我可以在其上运行 InstallUtil 并添加或删除计数器。
为了回答你的问题,我认为你不能单独操纵它们。 PerformanceCounterCategory 类似乎允许创建和删除,并且还能够获取关联的计数器,但不能修改它们并重新应用。
我认为无论如何这都是一个糟糕的方法,因为它给代码带来了额外的负担来管理这个问题。只需在需要时卸载并重新安装,并且拥有安装程序类使这变得非常容易。
In all my code, I always either create all counters, or delete them, but never modify them to add just one. Its not typically the thing to do as perf counters are usually installed once as part of the install of an app, or deleted once the app is removed. Again, I normally have an installer class so I can run InstallUtil over it and have the counters added or removed.
To answer your question, I dont think you can individually manipulate them. The PerformanceCounterCategory class seems to allow creation and deletion, and also the ability to get the associated counters, but not modify them and re-apply.
I think this would be a bad approach anyway as it places extra burden in the code to manage this. Just uninstall and re-install when needed and having an installer class makes this really easy.
我在寻找性能计数器相关问题的答案时遇到了这篇文章,所以我想我应该在这里更新。根据我在此 MSDN 页面,您无法更改现有类别,必须删除并重新创建。
I ran into this post in digging for an answer to a related issue I was having with performance counters, so I thought I'd update here. From what I read on this MSDN page, you cannot alter an existing category, you have to delete and recreate.
回答https://stackoverflow.com/a/4742793/52277问题如何将新计数器添加到现有性能计数器类别,而无需删除旧计数器? 描述如何在删除和重新创建类别之前保留计数器
Answer https://stackoverflow.com/a/4742793/52277 to the question How to add a new counter to an existing performance counter category without deleting the old counters? describes how to preserve counters before deleting and re-creating category