/// <summary> /// Uninstalls performance counters in the current assembly using PerfItFilterAttribute. /// </summary> /// <param name="installerAssembly"></param> /// <param name="categoryName">if you have provided a categoryName for the installation, you must supply the same here</param> public static void Uninstall(Assembly installerAssembly, string categoryName = null) { if (string.IsNullOrEmpty(categoryName)) { categoryName = installerAssembly.GetName().Name; } var httpActionDescriptorCategoryName = PerformanceCounterApmApiFilterAttribute.GetCategoryName(categoryName); try { if (PerformanceCounterCategory.Exists(httpActionDescriptorCategoryName)) { PerformanceCounterCategory.Delete(httpActionDescriptorCategoryName); } } catch (Exception ex) { Console.WriteLine(ex); } var httpClientCategoryName = PerformanceCounterApmHttpClientDelegatingHandler.GetCategoryName(categoryName); try { if (PerformanceCounterCategory.Exists(httpClientCategoryName)) { PerformanceCounterCategory.Delete(httpClientCategoryName); } } catch (Exception ex) { Console.WriteLine(ex); } var methodHanderCategoryName = PerformanceCounterApmMethodHandler.GetCategoryName(categoryName); try { if (PerformanceCounterCategory.Exists(methodHanderCategoryName)) { PerformanceCounterCategory.Delete(methodHanderCategoryName); } } catch (Exception ex) { Console.WriteLine(ex); } }
/// <summary> /// Installs performance counters in the current assembly using PerfItFilterAttribute. /// </summary> /// <param name="installerAssembly"></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, string categoryName = null) { if (string.IsNullOrEmpty(categoryName)) { categoryName = installerAssembly.GetName().Name; } Uninstall(installerAssembly, categoryName); var httpActionDescriptors = FindAllHttpActionDescriptors(installerAssembly).Distinct().ToArray(); var httpActionDescriptorCounters = GetCounterCreationDataCollectionForHttpActionDescriptors(httpActionDescriptors); var httpActionDescriptorCategoryName = PerformanceCounterApmApiFilterAttribute.GetCategoryName(categoryName); PerformanceCounterCategory.Create(httpActionDescriptorCategoryName, "APM api filter category for " + categoryName, PerformanceCounterCategoryType.MultiInstance, httpActionDescriptorCounters); Trace.TraceInformation("Built category '{0}' with {1} items", httpActionDescriptorCategoryName, httpActionDescriptorCounters.Count); //Todo: Need to rather use ApmContext.GetDelegatingHandler and ApmContext.GetMethodHander var apmContextUsage = FindAllApmContextUsage(installerAssembly).Distinct().ToArray(); var apmContextUsageCounters = GetCounterCreationDataCollectionForApmContextUsage(apmContextUsage); var httpClientCategoryName = PerformanceCounterApmHttpClientDelegatingHandler.GetCategoryName(categoryName); PerformanceCounterCategory.Create(httpClientCategoryName, "APM http client category for " + categoryName, PerformanceCounterCategoryType.MultiInstance, apmContextUsageCounters); Trace.TraceInformation("Built category '{0}' with {1} items", httpClientCategoryName, apmContextUsageCounters.Count); }