internal void Initialize(string instanceName) { if (!PerformanceCounterCategory.Exists(RelayNodeCounters.PerformanceCategoryName)) { InstallCounters(); } else { countersInitialized = true; ////check to see if all of the current counters are installed. //PerformanceCounterCategory perfCategory = new PerformanceCounterCategory(RelayNodeCounters.PerformanceCategoryName); //bool recreate = false; //foreach (string counterName in RelayNodeCounters.PerformanceCounterNames) //{ // if (!perfCategory.CounterExists(counterName)) // { // LoggingWrapper.Write("Counter " + counterName + " not found in category " + RelayNodeCounters.PerformanceCategoryName, "Relay"); // recreate = true; // break; // } //} //if (recreate) //{ // LoggingWrapper.Write("Recreating performance counter category " + RelayNodeCounters.PerformanceCategoryName, "Relay"); // RemoveCounters(); // InstallCounters(); //} //else //{ // countersInitialized = true; //} } try { if (countersInitialized) { int numCounters = PerformanceCounterNames.Length; PerformanceCounters = new PerformanceCounter[numCounters]; for (int i = 0; i < numCounters; i++) { PerformanceCounters[i] = new PerformanceCounter( PerformanceCategoryName, PerformanceCounterNames[i], instanceName, false ); } PerformanceCounter avgMsgLife = PerformanceCounters[(int)PerformanceCounterIndexes.AvgMsgLife]; PerformanceCounter avgMsgLifeBase = PerformanceCounters[(int)PerformanceCounterIndexes.AvgMsgLifeBase]; if (PerformanceCounterCategory.CounterExists(PerformanceCounterNames[(int)PerformanceCounterIndexes.AvgMsgLife], RelayNodeCounters.PerformanceCategoryName)) { avgMessageLife = new AverageMessageLife(avgMsgLife, avgMsgLifeBase); } if (PerformanceCounterCategory.CounterExists(PerformanceCounterNames[(int)PerformanceCounterIndexes.SaveWithConfirm], RelayNodeCounters.PerformanceCategoryName)) { _nov09CountersExist = true; if (PerformanceCounterCategory.CounterExists(PerformanceCounterNames[(int)PerformanceCounterIndexes.RedirectCount], RelayNodeCounters.PerformanceCategoryName)) { _july10CountersExist = true; } } if (!_july10CountersExist) { log.Warn("Some DataRelay performance counters are not installed, please reinstall DataRelay counters."); } hitCounter = new MinuteAggregateCounter(); attemptCounter = new MinuteAggregateCounter(); ResetCounters(); StartTimer(); } } catch (Exception ex) { if (log.IsErrorEnabled) { log.ErrorFormat("Exception creating Relay Node Counters: {0}. The counters might need to be reinstalled via InstallUtil.", ex); } countersInitialized = false; } }
internal void Initialize(string instanceName) { if (!PerformanceCounterCategory.Exists(RelayNodeCounters.PerformanceCategoryName)) { InstallCounters(); } else { countersInitialized = true; ////check to see if all of the current counters are installed. //PerformanceCounterCategory perfCategory = new PerformanceCounterCategory(RelayNodeCounters.PerformanceCategoryName); //bool recreate = false; //foreach (string counterName in RelayNodeCounters.PerformanceCounterNames) //{ // if (!perfCategory.CounterExists(counterName)) // { // LoggingWrapper.Write("Counter " + counterName + " not found in category " + RelayNodeCounters.PerformanceCategoryName, "Relay"); // recreate = true; // break; // } //} //if (recreate) //{ // LoggingWrapper.Write("Recreating performance counter category " + RelayNodeCounters.PerformanceCategoryName, "Relay"); // RemoveCounters(); // InstallCounters(); //} //else //{ // countersInitialized = true; //} } try { if (countersInitialized) { int numCounters = PerformanceCounterNames.Length; PerformanceCounters = new PerformanceCounter[numCounters]; for (int i = 0; i < numCounters; i++) { PerformanceCounters[i] = new PerformanceCounter( PerformanceCategoryName, PerformanceCounterNames[i], instanceName, false ); } PerformanceCounter avgMsgLife = PerformanceCounters[(int)PerformanceCounterIndexes.AvgMsgLife]; PerformanceCounter avgMsgLifeBase = PerformanceCounters[(int)PerformanceCounterIndexes.AvgMsgLifeBase]; if (PerformanceCounterCategory.CounterExists(PerformanceCounterNames[(int)PerformanceCounterIndexes.AvgMsgLife], RelayNodeCounters.PerformanceCategoryName)) { avgMessageLife = new AverageMessageLife(avgMsgLife, avgMsgLifeBase); } if (PerformanceCounterCategory.CounterExists(PerformanceCounterNames[(int)PerformanceCounterIndexes.SaveWithConfirm], RelayNodeCounters.PerformanceCategoryName)) { nov09CountersExist = true; } else { log.Warn("Confirmed Update Counters are not installed, please reinstall DataRelay counters."); } hitCounter = new MinuteAggregateCounter(); attemptCounter = new MinuteAggregateCounter(); ResetCounters(); StartTimer(); } } catch(Exception ex) { if (log.IsErrorEnabled) log.ErrorFormat("Exception creating Relay Node Counters: {0}. The counters might need to be reinstalled via InstallUtil.", ex); countersInitialized = false; } }