/// <summary> /// Registers a counter using the counter name and reportAs value to the total list of counters. /// </summary> /// <param name="perfCounter">Name of the performance counter.</param> /// <param name="reportAs">Report as name for the performance counter.</param> /// <param name="isCustomCounter">Boolean to check if the performance counter is custom defined.</param> /// <param name="error">Captures the error logged.</param> /// <param name="blockCounterWithInstancePlaceHolder">Boolean that controls the registry of the counter based on the availability of instance place holder.</param> public void RegisterCounter( string perfCounter, string reportAs, bool isCustomCounter, out string error, bool blockCounterWithInstancePlaceHolder) { try { bool useInstancePlaceHolder = false; var pc = PerformanceCounterUtility.CreateAndValidateCounter(perfCounter, null, null, out useInstancePlaceHolder, out error); if (pc != null) { this.RegisterPerformanceCounter(perfCounter, this.GetCounterReportAsName(perfCounter, reportAs), pc.CategoryName, pc.CounterName, pc.InstanceName, useInstancePlaceHolder, false); } else { // Even if validation failed, we might still be able to collect perf counter in WebApp. this.RegisterPerformanceCounter(perfCounter, this.GetCounterReportAsName(perfCounter, reportAs), string.Empty, perfCounter, string.Empty, useInstancePlaceHolder, false); } } catch (Exception e) { PerformanceCollectorEventSource.Log.WebAppCounterRegistrationFailedEvent( e.Message, perfCounter); error = e.Message; } }
/// <summary> /// Refreshes the counter associated with a specific performance counter data. /// </summary> /// <param name="pcd">Target performance counter data to refresh.</param> private void RefreshCounter(PerformanceCounterData pcd) { string dummy; bool usesInstanceNamePlaceholder; var pc = PerformanceCounterUtility.CreateAndValidateCounter( pcd.OriginalString, this.win32Instances, this.clrInstances, out usesInstanceNamePlaceholder, out dummy); try { this.RefreshPerformanceCounter(pcd); PerformanceCollectorEventSource.Log.CounterRegisteredEvent( PerformanceCounterUtility.FormatPerformanceCounter(pc)); } catch (InvalidOperationException e) { PerformanceCollectorEventSource.Log.CounterRegistrationFailedEvent( e.Message, PerformanceCounterUtility.FormatPerformanceCounter(pc)); } }
/// <summary> /// Registers a counter using the counter name and reportAs value to the total list of counters. /// </summary> /// <param name="perfCounterName">Name of the performance counter.</param> /// <param name="reportAs">Report as name for the performance counter.</param> /// <param name="isCustomCounter">Boolean to check if the performance counter is custom defined.</param> /// <param name="error">Captures the error logged.</param> /// <param name="blockCounterWithInstancePlaceHolder">Boolean that controls the registry of the counter based on the availability of instance place holder.</param> public void RegisterCounter( string perfCounterName, string reportAs, bool isCustomCounter, out string error, bool blockCounterWithInstancePlaceHolder = false) { bool usesInstanceNamePlaceholder; if (!this.dependendentInstancesLoaded) { this.LoadDependentInstances(); this.dependendentInstancesLoaded = true; } var pc = PerformanceCounterUtility.CreateAndValidateCounter( perfCounterName, this.win32Instances, this.clrInstances, out usesInstanceNamePlaceholder, out error); // If blockCounterWithInstancePlaceHolder is true, then we register the counter only if usesInstanceNamePlaceHolder is true. if (pc != null && !(blockCounterWithInstancePlaceHolder && usesInstanceNamePlaceholder)) { this.RegisterCounter(perfCounterName, reportAs, pc, isCustomCounter, usesInstanceNamePlaceholder, out error); } }
/// <summary> /// Registers a counter using the counter name and reportAs value to the total list of counters. /// </summary> /// <param name="perfCounter">Name of the performance counter.</param> /// <param name="reportAs">Report as name for the performance counter.</param> /// <param name="isCustomCounter">Boolean to check if the performance counter is custom defined.</param> /// <param name="error">Captures the error logged.</param> /// <param name="blockCounterWithInstancePlaceHolder">Boolean that controls the registry of the counter based on the availability of instance place holder.</param> public void RegisterCounter( string perfCounter, string reportAs, bool isCustomCounter, out string error, bool blockCounterWithInstancePlaceHolder) { error = null; try { bool useInstancePlaceHolder = false; string parsingError = null; var pc = PerformanceCounterUtility.CreateAndValidateCounter(perfCounter, null, null, out useInstancePlaceHolder, out parsingError); if (!string.IsNullOrEmpty(parsingError)) { error = parsingError; } if (pc != null) { this.RegisterPerformanceCounter(perfCounter, this.GetCounterReportAsName(perfCounter, reportAs), pc.CategoryName, pc.CounterName, pc.InstanceName, useInstancePlaceHolder, false); } else { this.RegisterPerformanceCounter(perfCounter, this.GetCounterReportAsName(perfCounter, reportAs), string.Empty, perfCounter, string.Empty, useInstancePlaceHolder, false); } } catch (Exception e) { PerformanceCollectorEventSource.Log.WebAppCounterRegistrationFailedEvent( e.Message, perfCounter); error = e.Message; } }