dotnet/runtime

APP_POOL_WAS perfomanceCounter always returns 0

Open

#47.636 geöffnet am 29. Jan. 2021

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (5.445 Forks)batch import
area-System.Diagnostics.PerformanceCounterbacklog-cleanup-candidatehelp wantedno-recent-activity

Repository-Metriken

Stars
 (17.886 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 12T 11h) (661 gemergte PRs in 30 T)

Beschreibung

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

Contributor Guide