public class MathServicePerfCounter : IPerfCounterProvider { static MathServicePerfCounter _instance = PerfCounterFactory.GetCounters<MathServicePerfCounter>(); public static MathServicePerfCounter Instance { get { return _instance; } } public PerformanceCounter TotalOfRequest; public PerformanceCounter RateOfRequest; public PerformanceCounter RateOfAddition; public PerformanceCounter RateOfMultiplication; public PerformanceCounter CountOfCurrentRequest; const string TotalOfRequestStr = "Total # req"; const string RateOfRequestStr = "req/sec"; const string RateOfAdditionStr = "Addition/sec"; const string RateOfMultiplicationStr = "Multiplication/sec"; const string CountOfCurrentRequestStr = "current # req"; #region IPerfCounterProvider 成员 public void CreateCounters() { PerfCounterFactory.AddPerfCounter(new PerfCounter(TotalOfRequestStr, "请求总数", PerformanceCounterType.NumberOfItems64)); PerfCounterFactory.AddPerfCounter(new PerfCounter(RateOfRequestStr, "每秒请求的数量", PerformanceCounterType.RateOfCountsPerSecond64)); PerfCounterFactory.AddPerfCounter(new PerfCounter(RateOfAdditionStr, "每秒相加请求的数量", PerformanceCounterType.RateOfCountsPerSecond64)); PerfCounterFactory.AddPerfCounter(new PerfCounter(RateOfMultiplicationStr, "每秒相成的数量", PerformanceCounterType.RateOfCountsPerSecond64)); PerfCounterFactory.AddPerfCounter(new PerfCounter(CountOfCurrentRequestStr, "当前并发请求量", PerformanceCounterType.RateOfCountsPerSecond64)); } public void CountersCreated() { TotalOfRequest = PerfCounterFactory.Find(TotalOfRequestStr); RateOfRequest = PerfCounterFactory.Find(RateOfRequestStr); RateOfAddition = PerfCounterFactory.Find(RateOfAdditionStr); RateOfMultiplication = PerfCounterFactory.Find(RateOfMultiplicationStr); CountOfCurrentRequest = PerfCounterFactory.Find(CountOfCurrentRequestStr); } public string PerformanceObjectName() { return "MathServicePerfCounter"; } #endregion }