public void RegisterCategory(CategoryConfiguration categoryConfiguration) { if (!PerformanceCounterCategory.Exists(categoryConfiguration.Name)) { PerformanceCounterCategory.Create( categoryConfiguration.Name, categoryConfiguration.Help, PerformanceCounterCategoryType.MultiInstance, new CounterCreationDataCollection( categoryConfiguration.Counters.Select(x => (CounterCreationData)x).ToArray())); return; } CleanUpCategory(categoryConfiguration); }
void Register(Type counterCategoryType) { var category = new CategoryConfiguration { Name = counterCategoryType.Name }; var props = counterCategoryType.GetProperties(); foreach (var propertyInfo in props) { var counter = new PerformanceCounterConfiguration(propertyInfo.Name, "no-counter-help-yet", PerformanceCounterType.NumberOfItems32); category.Counters.Add(counter); } _categoryConfigurations.Add(category); }
static void CleanUpCategory(CategoryConfiguration categoryConfiguration) { int missing = categoryConfiguration.Counters .Where(counter => !PerformanceCounterCategory.CounterExists(counter.Name, categoryConfiguration.Name)) .Count(); if (missing > 0) { PerformanceCounterCategory.Delete(categoryConfiguration.Name); PerformanceCounterCategory.Create( categoryConfiguration.Name, categoryConfiguration.Help, PerformanceCounterCategoryType.MultiInstance, new CounterCreationDataCollection( categoryConfiguration.Counters.Select(x => (CounterCreationData)x).ToArray())); } }