dotnet/runtime

APP_POOL_WAS perfomanceCounter always returns 0

Open

#47 636 ouverte le 29 janv. 2021

Voir sur GitHub
 (2 commentaires) (0 réactions) (0 assignés)C# (5 445 forks)batch import
area-System.Diagnostics.PerformanceCounterbacklog-cleanup-candidatehelp wantedno-recent-activity

Métriques du dépôt

Stars
 (17 886 stars)
Métriques de merge PR
 (Merge moyen 12j 11h) (661 PRs mergées en 30 j)

Description

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

Guide contributeur