【问题标题】:PerformanceCounter Category does not exist even though it existsPerformanceCounter 类别不存在,即使它存在
【发布时间】:2015-07-10 19:44:09
【问题描述】:

我的 IIS 机器上运行了一个 Azure Web 角色和一个单独的 Windows 服务。 Web 角色创建一个自定义性能计数器类别和两个计数器。我正在尝试从我的 Windows 服务中读取性能计数器。即使PerformanceCounterCategory.Exists(categoryName) 返回trueGetCounters 方法也会抛出异常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


    【解决方案1】:

    我们遇到了同样的问题。 实际 WindowsInstance 中的整个 PerformanceCounters 有问题。 我们通过这个 CMD 命令解决了它(以管理员身份运行):

    lodctr /R
    

    它从一些备份存储中重建了 PerformanceCounters。

    如果它不能解决您的问题,您可以试试这个(再次使用具有管理员权限的 CMD):

    Winmgmt /resyncperf 
    Net stop winmgmt /y 
    Net start winmgmt
    

    来源:https://thwack.solarwinds.com/thread/43987

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      相关资源
      最近更新 更多