dotnet/runtime

APP_POOL_WAS perfomanceCounter always returns 0

Open

#47,636 建立於 2021年1月29日

在 GitHub 查看
 (2 留言) (0 反應) (0 負責人)C# (5,445 fork)batch import
area-System.Diagnostics.PerformanceCounterbacklog-cleanup-candidatehelp wantedno-recent-activity

倉庫指標

Star
 (17,886 star)
PR 合併指標
 (平均合併 12天 11小時) (30 天內合併 661 個 PR)

描述

Description

I trying to get uptime for IIS AppPool, but code always returns zero. Windows system monitor shows real values:

image

Code:

PerformanceCounterCategory cat = new PerformanceCounterCategory("APP_POOL_WAS");
string inst = cat.GetInstanceNames().First(x => x.Contains("bp"));
PerformanceCounter pc = cat.GetCounters(inst).First(x => x.CounterName == "Current Application Pool Uptime");
pc.NextValue(); //zero 
Thread.Sleep(1000); //wait as recommended in msdn
float val = pc.NextValue(); //zero too

Configuration

aspnet core 3.1 (net 5.0 - same behavior) windows 10 x64, self-hosted

Expected behavior

Like as, for example, "System - System Up Time" Perfomance counter:

PerformanceCounter _upTimeCounter = new PerformanceCounter("System", "System Up Time");
_upTimeCounter.NextValue(); //zero
TimeSpan uptimeCounterValue = TimeSpan.FromSeconds(_upTimeCounter.NextValue()); //real expected value

Extended information

All counters in category "APP_POOL_WAS" with type PerformanceCounterType.ElapsedTime returns zero. All others returns real values

Maybe this is localization error, because in powershell we see localizaed names of counters

image

貢獻者指南