public PerformanceCounterCategoryMetadata() { CacheRequests = new PerformanceCounterMetadata() { Name = "Cache Requests", Description = "Total requests made to cache", Type = PerformanceCounterType.NumberOfItems64, Category = this }; CacheHits = new PerformanceCounterMetadata() { Name = "Cache Hits", Description = "Total cache hits", Type = PerformanceCounterType.NumberOfItems64, Category = this }; CacheMisses = new PerformanceCounterMetadata() { Name = "Cache Misses", Description = "Total cache misses", Type = PerformanceCounterType.NumberOfItems64, Category = this }; Counters = new List <PerformanceCounterMetadata>() { CacheRequests, CacheHits, CacheMisses }; }
public static void IncrementCount(PerformanceCounterMetadata counter) { EnsureCounter(counter); if (counter.Type == PerformanceCounterType.NumberOfItems64) { if (_Counters.ContainsKey(counter.FullName)) { try { _Counters[counter.FullName].Increment(); } catch (Exception ex) { Log.Debug("Instrumentation.IncrementCounter failed for: {0}. Error: {1}", counter.FullName, ex.FullMessage()); } } } }
private static void EnsureCounter(PerformanceCounterMetadata counter) { if (!_Counters.ContainsKey(counter.FullName)) { try { if (!PerformanceCounterCategory.Exists(counter.Category.Name)) { CreateCounters(counter.Category); } _Counters[counter.FullName] = new diag.PerformanceCounter(counter.Category.Name, counter.Name, false); } catch (Exception ex) { Log.Warn("Instrumentation.EnsureCounters failed to initialise performance counter: {0}. Counter may not be initialised. Error: {1}", counter.Name, ex.FullMessage()); } } }