【发布时间】:2015-07-10 19:44:09
【问题描述】:
我的 IIS 机器上运行了一个 Azure Web 角色和一个单独的 Windows 服务。 Web 角色创建一个自定义性能计数器类别和两个计数器。我正在尝试从我的 Windows 服务中读取性能计数器。即使PerformanceCounterCategory.Exists(categoryName) 返回true,GetCounters 方法也会抛出异常Category does not exist(请参阅更新)。
if (PerformanceCounterCategory.Exists(categoryName))
{
try
{
// Get the existing category and counters
PerformanceCounterCategory existingCategory = new PerformanceCounterCategory(categoryName);
counters = existingCategory.GetCounters();
}
catch (Exception e)
{
Debug.WriteLine("Failed to read the performance category {0}. Exception: {1}", categoryName, e.Message);
}
}
Windows 服务作为本地系统服务运行,因此我认为它应该具有特权。事实上,我可以通过 Visual Studio 的服务器资源管理器查看性能类别和计数器。
如果类别不存在,我应该预计 PerformanceCounterCategory.Exists(categoryName) 首先会失败,对吧?
更新
- 我也看到
GetCounters方法抛出InvalidOperationException和消息Could not Read Category Index: {some index here}.。 - Similar issuemsdn 论坛发帖
- 同样的进程可以正常读取计数器。
【问题讨论】:
标签: c# windows performance azure monitoring