È possibile utilizzare la classe PerformanceCounter, cioè int System.System.Diagnostics namespace.
aggiungere la tua categoria e Controriforma, si usa un codice come questo:
if (!PerformanceCounterCategory.Exists("AverageCounter64SampleCategory"))
{
CounterCreationDataCollection CCDC = new CounterCreationDataCollection();
// Add the counter.
CounterCreationData averageCount64 = new CounterCreationData();
averageCount64.CounterType = PerformanceCounterType.AverageCount64;
averageCount64.CounterName = "AverageCounter64Sample";
CCDC.Add(averageCount64);
// Add the base counter.
CounterCreationData averageCount64Base = new CounterCreationData();
averageCount64Base.CounterType = PerformanceCounterType.AverageBase;
averageCount64Base.CounterName = "AverageCounter64SampleBase";
CCDC.Add(averageCount64Base);
// Create the category.
PerformanceCounterCategory.Create("AverageCounter64SampleCategory",
"Demonstrates usage of the AverageCounter64 performance counter type.",
CCDC);
}
Per azzerare un contatore, è possibile reimpostare rawValue-0, in questo modo:
var pc = new PerformanceCounter("AverageCounter64SampleCategory",
"AverageCounter64Sample",
false);
pc.RawValue = 0;
Questi codici di esempio sopra ho ottenuto da questo collegamento: system.diagnostics.performancecounter
Spero che aiuti.
fonte
2015-07-29 14:07:58
Hai visto questa pagina: http://www.codeproject.com/Articles/8590/An-Introduction-To-Performance-Counters? Sono d'accordo con Anton Gogolev, i contatori di prestazioni possono essere un problema, li ho visti diventare "corrotti" a una dozzina di server (non solo i contatori che stavo cercando di aggiungere). –