/// <summary> /// Installs performance counters in the assembly /// </summary> /// <param name="installerAssembly"></param> /// <param name="discoverer">object that can discover aspects inside and assembly</param> /// <param name="categoryName">category name for the metrics. If not provided, it will use the assembly name</param> public static void Install(Assembly installerAssembly, IInstrumentationDiscoverer discoverer, string categoryName = null) { Uninstall(installerAssembly, discoverer, categoryName); if (string.IsNullOrEmpty(categoryName)) categoryName = installerAssembly.GetName().Name; var instrumentationInfos = discoverer.Discover(installerAssembly).ToArray(); if (instrumentationInfos.Length == 0) { throw new InvalidOperationException("There are no instrumentationInfos found by the discoverer!"); } var counterCreationDataCollection = new CounterCreationDataCollection(); Trace.TraceInformation("Number of filters: {0}", instrumentationInfos.Length); foreach (var group in instrumentationInfos.GroupBy(x => x.CategoryName)) { foreach (var instrumentationInfo in group) { Trace.TraceInformation("Setting up filters '{0}'", instrumentationInfo.Description); if (instrumentationInfo.Counters == null || instrumentationInfo.Counters.Length == 0) instrumentationInfo.Counters = CounterTypes.StandardCounters; foreach (var counterType in instrumentationInfo.Counters) { if (!HandlerFactories.ContainsKey(counterType)) throw new ArgumentException("Counter type not defined: " + counterType); // if already exists in the set then ignore if (counterCreationDataCollection.Cast<CounterCreationData>().Any(x => x.CounterName == counterType)) { Trace.TraceInformation("Counter type '{0}' was duplicate", counterType); continue; } using (var counterHandler = HandlerFactories[counterType](categoryName, instrumentationInfo.InstanceName)) { counterCreationDataCollection.AddRange(counterHandler.BuildCreationData()); Trace.TraceInformation("Added counter type '{0}'", counterType); } } } var catName = string.IsNullOrEmpty(group.Key) ? categoryName : group.Key; PerformanceCounterCategory.Create(catName, "PerfIt category for " + catName, PerformanceCounterCategoryType.MultiInstance, counterCreationDataCollection); } Trace.TraceInformation("Built category '{0}' with {1} items", categoryName, counterCreationDataCollection.Count); }
/// <summary> /// Installs performance counters in the assembly /// </summary> /// <param name="installerAssembly"></param> /// <param name="discoverer">object that can discover aspects inside and assembly</param> /// <param name="categoryName">category name for the metrics. If not provided, it will use the assembly name</param> public static void Install(Assembly installerAssembly, IInstrumentationDiscoverer discoverer, string categoryName = null) { Uninstall(installerAssembly, discoverer, categoryName); if (string.IsNullOrEmpty(categoryName)) { categoryName = installerAssembly.GetName().Name; } var instrumentationInfos = discoverer.Discover(installerAssembly).ToArray(); if (instrumentationInfos.Length == 0) { throw new InvalidOperationException("There are no instrumentationInfos found by the discoverer!"); } var counterCreationDataCollection = new CounterCreationDataCollection(); Trace.TraceInformation("Number of filters: {0}", instrumentationInfos.Length); foreach (var group in instrumentationInfos.GroupBy(x => x.CategoryName)) { foreach (var instrumentationInfo in group) { Trace.TraceInformation("Setting up filters '{0}'", instrumentationInfo.Description); foreach (var counterType in instrumentationInfo.Counters) { if (!HandlerFactories.ContainsKey(counterType)) { throw new ArgumentException("Counter type not defined: " + counterType); } // if already exists in the set then ignore if (counterCreationDataCollection.Cast <CounterCreationData>().Any(x => x.CounterName == counterType)) { Trace.TraceInformation("Counter type '{0}' was duplicate", counterType); continue; } using (var counterHandler = HandlerFactories[counterType](categoryName, instrumentationInfo.InstanceName)) { counterCreationDataCollection.AddRange(counterHandler.BuildCreationData().ToArray()); Trace.TraceInformation("Added counter type '{0}'", counterType); } } } var catName = string.IsNullOrEmpty(group.Key) ? categoryName : group.Key; PerformanceCounterCategory.Create(catName, "PerfIt category for " + catName, PerformanceCounterCategoryType.MultiInstance, counterCreationDataCollection); } Trace.TraceInformation("Built category '{0}' with {1} items", categoryName, counterCreationDataCollection.Count); }
public static void Uninstall(Assembly installerAssembly, IInstrumentationDiscoverer discoverer, string categoryName = null) { if (string.IsNullOrEmpty(categoryName)) { categoryName = installerAssembly.GetName().Name; } var perfItFilterAttributes = discoverer.Discover(installerAssembly).ToArray(); Trace.TraceInformation("Number of filters: {0}", perfItFilterAttributes.Length); foreach (var group in perfItFilterAttributes.GroupBy(x => x.CategoryName)) { var catName = string.IsNullOrEmpty(group.Key) ? categoryName : group.Key; Trace.TraceInformation("Deleted category '{0}'", catName); Uninstall(catName); } }
public static void Uninstall(Assembly installerAssembly, IInstrumentationDiscoverer discoverer, string categoryName = null) { if (string.IsNullOrEmpty(categoryName)) categoryName = installerAssembly.GetName().Name; var perfItFilterAttributes = discoverer.Discover(installerAssembly).ToArray(); Trace.TraceInformation("Number of filters: {0}", perfItFilterAttributes.Length); foreach (var group in perfItFilterAttributes.GroupBy(x => x.CategoryName)) { var catName = string.IsNullOrEmpty(group.Key) ? categoryName : group.Key; Trace.TraceInformation("Deleted category '{0}'", catName); Uninstall(catName); } }
public static void Uninstall(Assembly installerAssembly, IInstrumentationDiscoverer discoverer, string categoryName = null) { CounterInstaller.Uninstall(installerAssembly, discoverer, categoryName); }