我目前在Windows系统上运行nginx,并正在制作一个小的控制面板来显示Web服务器的统计信息。
我正在尝试获取该进程的CPU使用率和内存使用率的性能计数器,但是nginx显示为多个进程,根据配置文件中的设置,它的范围从2到5不等。我的设置显示了两个进程,因此nginx.exe和nginx.exe
[我知道要使用哪些性能计数器% Processor Time
和Working Set - Private
,但我将如何获得两个进程的单个值,以便将它们加在一起以获得最终值?
我尝试使用在Waffles question处找到的代码,但它只能输出两个过程中第一个过程的值。
谢谢。
编辑-工作代码
for (int i = 0; i < instances.Length; i++)
{
//i = i + 1;
if (i == 0)
{
toPopulate = new PerformanceCounter
("Process", "Working Set - Private",
toImport[i].ProcessName,
true);
}
else
{
toPopulate = new PerformanceCounter
("Process", "Working Set - Private",
toImport[i].ProcessName + "#" + i,
true);
}
totalNginRam += toPopulate.NextValue();
instances[i] = toPopulate;
}
请看该问题的公认答案。尝试运行perfmon
。具有相同名称的进程将被标识为类似process#1
,process#2
等的名称。在您的情况下,可能是nginx#1
,nginx#2
等。>
编辑:
您需要将实例名称传递给适当的constructor overload或InstanceName
属性。根据this,看起来正确的格式是使用下划线。因此,process_1
,process_2
。
使用Azure Log Analytics时,您可以指定一个路径,例如