C# 性能计数器:“;数据库缓存%Hit";
我使用这段代码检索要监视的机器上的可用性能计数器:C# 性能计数器:“;数据库缓存%Hit";,c#,performancecounter,C#,Performancecounter,我使用这段代码检索要监视的机器上的可用性能计数器: var allCounters = new List<PerformanceCounter>(); foreach (var category in PerformanceCounterCategory.GetCategories("machine-name")) { var names = category.GetInstanceNames();
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());
}
}
直到我对其调用NextValue
方法,该方法将引发invalidoOperationException
:
Counter is not single instance, an instance name needs to be specified.
我尝试输入要监视的SQL Server DB名称,但也不起作用(而是在实例化过程中失败)
如何在我的C#应用程序中使用此性能计数器?不幸的是,“数据库”计数器组与SQL server无关。它是基础设施的一部分
有关SQL server统计信息,请查找MSSQL$instance\u name
计数器。可能您正在寻找缓冲区管理器缓存命中率,但是还有其他缓存(如查询计划缓存)
此外,您可能希望直接从
sys.dm_os_performance_counters
视图中查询统计信息,绕过这个过多的windows计数器层…在运行中键入perfmon.exe
,并查看数据库-->数据库缓存下有多少实例命中了计数器。显然不止一个。在我的电脑上,是的。在远程计算机上,否:/perfmon中没有显示实例名称。也许计数器本身坏了,因为performan甚至不能监视它。我应该补充一点,远程机器是一个托管在HyperV上的VM,如果这改变了什么的话。谢谢你提供的信息!但是,我找不到任何名为MSSQL
或SQLServer
的类别(我在视图中看到它们,但在perfmon或我的代码中看不到):在远程上运行lodctr/R
,没有帮助。我猜HyperV在某些地方出了问题……甚至HyperV也允许您直接查询数据)
Counter is not single instance, an instance name needs to be specified.