【问题标题】:Performance Counter : "Database Cache % Hit"性能计数器:“数据库缓存百分比命中”
【发布时间】:2014-12-08 22:44:11
【问题描述】:

我使用这段代码来检索我要监控的机器上的可用性能计数器:

        var allCounters = new List<PerformanceCounter>();
        foreach (var category in PerformanceCounterCategory.GetCategories("machine-name"))
        {
            var names = category.GetInstanceNames();
            if (names.Length > 0)
            {
                foreach (var name in names)
                {
                    allCounters.AddRange(category.GetCounters(name));
                }
            }
            else
            {
                allCounters.AddRange(category.GetCounters());
            }
        }

我找到了一个我想监控的计数器:Database Cache % Hit。它没有任何实例名称,所以我就是这样理解的:

new PerformanceCounter("Database", "Database Cache % Hit", null, "machine-name"); //null or "" for the third argument

这一直有效,直到我在其上调用 NextValue 方法,这会引发 InvalidOperationException

Counter is not single instance, an instance name needs to be specified.

我尝试输入要监视的 SQL Server 数据库名称的名称,但它也不起作用(而是在实例化期间失败)。

如何在我的 C# 应用程序中使用此性能计数器?

【问题讨论】:

  • run 中键入 perfmon.exe 并查看您的 Database --&gt; Database Cache % Hit 计数器下有多少实例。显然不止一个。
  • 在我的电脑上,是的。在远程机器上,不:/ perfmon 中没有显示实例名称。也许计数器本身坏了,因为 perfoman 甚至无法监控它。我应该补充一点,远程机器是托管在 HyperV 上的 VM,如果这有任何改变的话。

标签: c# performancecounter


【解决方案1】:

不幸的是,“数据库”计数器组与 SQL 服务器无关。它是ESENT 基础设施的一部分。

对于 SQL 服务器统计信息,请查找 MSSQL$instance_name 计数器。可能您正在寻找缓冲区管理器缓存命中率,但是还有其他缓存(例如查询计划缓存)。

您可能还想直接从sys.dm_os_performance_counters 视图查询统计信息,绕过这个过多的 Windows 计数器层...

【讨论】:

  • 感谢您的信息!但是我找不到任何名为MSSQLSQLServer 的类别(我在视图中看到它们,但在perfmon 和我的代码中都没有):在遥控器上运行lodctr /R,没有帮助。我猜 HyperV 的某个地方出了点问题。
  • ……甚至HyperV都祝福你直接查询数据)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-10
  • 2015-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多