简体   繁体   中英

Performance counters over custom period of time

I need to be able to collect some performance counters over a specific custom period of time. I'm interested in particular in a couple of perf counters from ServiceModelService: "Calls" and "Failed Calls", although the question applies to any one I believe.

Out of the box, WCF offers "Calls" with the total number since the service started and "Calls per second"; same for "Failed Calls", "Failed Calls per second". What I need is to be able to create this for a custom period of time, for example "Calls per minute" or "Calls per hour".

I haven't seen any out of the box way of doing this. I guess I could create my own perf counter gatherer which will be making the calculations every X amount of time; my application is running in an Azure Cloud Service, so I believe this could be done in a separate exe installed in a startup task, or in a separate thread spawned when the web role starts.

I phrased the question in my own specific problem, but I believe the question applies to any scenario: how to capture perf counters over a specific custom period of time.

Any help would be very appreciated! Thanks!

So it turns out that the "Calls per second" and "Failed Calls per second" performance counters names are a bit misleading... Their default sample rate is 1s, but they are able to work for whatever sample interval rate you need. For instance, if you want to know the number of calls that happened in five seconds you can write code like this:

// load performance counter
var numOfCalls = new PerformanceCounter(...);

// read initial value for the period
numOfCalls.NextValue();

// wait desired period
Thread.Sleep(5000);

// read final value, the counter will internally calculate it based on the two samples
numOfCalls.NextValue();

If you're using perfmon you can just change the sample rate; if you're using code then you can just set the sample rate yourself by spacing the NextValue calls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM