2011-10-08 45 views
3

我目前在我的Windows系統上運行nginx,並且正在製作一個小控制面板來顯示我的web服務器的統計信息。具有相同名稱的所有進程的性能計數器?

我試圖獲得性能計數器的CPU使用率和內存使用率的過程,但nginx顯示爲多個進程,它可以從2 - 5取決於配置文件中的設置不同。我的設置顯示了兩個過程,所以nginx.exe和nginx.exe

我知道是幹什麼用的性能計數器,% Processor TimeWorking 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; 
        } 

回答

1

看那接受這個問題的答案。嘗試運行perfmon。具有相同名稱的過程將被確定爲這樣的事process#1process#2,等你的情況可能是nginx#1nginx#2

編輯:

您需要的實例名稱傳遞給任相應的constructor overloadInstanceName屬性。根據this,看起來正確的格式是使用下劃線。所以,process_1process_2

+0

如果它是nginx#2我怎麼能夠選擇它作爲標識符? –

+0

檢查perfmon它顯示爲nginx和nginx#1 –

+0

請參閱我的編輯。所以使用'nginx'或者'nginx_1'。 –