I was recently introduced to creating performance counters in C#. It seems very enticing, but upon exploring the classes available to me, I realized that I don't understand what I am doing.
I have been able to create a Performance Counter Category and add some custom counters. I can even see the results in perfmon. My problem is that I don't understand if and how I am supposed to calculate many of the counters.
Some of them are simple. I have been able to use NumberOfItems32 to track the number of times a web service method gets called over the course of time. All I do is call Increment(). In this case I believe I understand how it is supposed to work.
Where I am more confused is on the "Average" and "Percentage" types of counters. Take the Counter Timer, for instance. According to the documentation, that type of counter is:"
"A percentage counter that shows the average time that a component is active as a percentage of the total sample time.Formula: (N 1 - N 0) / (D 1 - D 0), where N1 and N 0 are performance counter readings, and D 1 and D 0 are their corresponding time readings. Thus, the numerator represents the portions of the sample interval during which the monitored components were active, and the denominator represents the total elapsed time of the sample interval."
My question is, do I need to calculate that information or does the framework do it when I simply call Increment()? Do I need to provide the values for the formula and do an IncrementBy()? If I have to perform the calculations myself, what are these methods actually doing besides logging the value to perfmon?
Every sample I see o fusing the CounterTimer counter does something like IncrementBy(random * elapsedTime). Can someone show me a decent example of how to use this counter in a practical way rather than just using some random value?
I realize this is a pretty broad question, but its mostly because I really don't understand how counters work.
Thanks!