通过 PerformanceCounterCategory 添加计数器

发布于 2024-10-28 01:27:18 字数 106 浏览 2 评论 0原文

你好 使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦幻之岛 2024-11-04 01:27:19

在我的所有代码中,我总是要么创建所有计数器,要么删除它们,但绝不会修改它们以仅添加一个。它通常不是要做的事情,因为性能计数器通常作为应用程序安装的一部分安装一次,或者在应用程序删除后删除。同样,我通常有一个安装程序类,因此我可以在其上运行 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.

波浪屿的海角声 2024-11-04 01:27:19

我在寻找性能计数器相关问题的答案时遇到了这篇文章,所以我想我应该在这里更新。根据我在此 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.

...you must create a counter in a new category; adding a counter to an
existing user-defined category will raise an exception.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文