Exemplo n.º 1
0
        internal void Initialize(string instanceName)
        {
            try
            {
                if (!PerformanceCounterCategory.Exists(PerformanceCategoryName))
                {
                    InstallCounters();
                }
                else
                {
                    _countersInitialized = true;
                    //the below seems to have issues upon reinitialization. Just force using the installer.
                    ////check to see if all of the current counters are installed.
                    //PerformanceCounterCategory perfCategory = new PerformanceCounterCategory(ForwardingCounters.PerformanceCategoryName);
                    //bool recreate = false;

                    //foreach (string counterName in ForwardingCounters.PerformanceCounterNames)
                    //{
                    //    if (!perfCategory.CounterExists(counterName))
                    //    {
                    //        LoggingWrapper.Write("Counter " + counterName + " not found in category " + ForwardingCounters.PerformanceCategoryName, "Relay");
                    //        recreate = true;
                    //        break;
                    //    }
                    //}
                    //if (recreate)
                    //{
                    //    LoggingWrapper.Write("Recreating performance counter category " + ForwardingCounters.PerformanceCategoryName, "Relay");
                    //    RemoveCounters();
                    //    InstallCounters();
                    //}
                    //else
                    //{
                    //    countersInitialized = true;
                    //}
                }
                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
                            );
                    }

                    if (PerformanceCounterCategory.CounterExists(PerformanceCounterNames[(int)PerformanceCounterIndexes.AvgMsgLife],
                                                                 PerformanceCategoryName))
                    {
                        _avgMessageLife = new AverageMessageLife(
                            PerformanceCounters[(int)PerformanceCounterIndexes.AvgMsgLife],
                            PerformanceCounters[(int)PerformanceCounterIndexes.AvgMsgLifeBase]);
                    }

                    if (PerformanceCounterCategory.CounterExists(PerformanceCounterNames[(int)PerformanceCounterIndexes.SaveWithConfirm],
                                                                 PerformanceCategoryName))
                    {
                        nov09CountersExist = true;

                        if (PerformanceCounterCategory.CounterExists(PerformanceCounterNames[(int)PerformanceCounterIndexes.PersistentErrorQueueBytes],
                                                                     PerformanceCategoryName))
                        {
                            nov10CountersExist = true;
                        }
                    }

                    if (!nov09CountersExist || !nov10CountersExist)
                    {
                        _log.Warn("Current performance counters are not installed, please reinstall DataRelay counters.");
                    }

                    _hitCounter     = new MinuteAggregateCounter();
                    _attemptCounter = new MinuteAggregateCounter();
                    ResetCounters();
                    StartTimer();
                }
            }
            catch (System.Security.SecurityException)
            {
                if (_log.IsWarnEnabled)
                {
                    _log.Warn("Could not automatically install relay forwarding counters. Please run InstallUtil against MySpace.RelayComponent.Forwarding.dll to install counters manually.");
                }
                _countersInitialized = false;
            }
            catch (UnauthorizedAccessException)
            {
                if (_log.IsWarnEnabled)
                {
                    _log.Warn("Could not automatically install relay forwarding counters. Please run InstallUtil against MySpace.RelayComponent.Forwarding.dll to install counters manually.");
                }
                _countersInitialized = false;
            }
            catch (Exception ex)
            {
                if (_log.IsErrorEnabled)
                {
                    _log.ErrorFormat("Error initializing relay forwarding counters: {0}", ex);
                }
                _countersInitialized = false;
            }
        }
		internal void Initialize(string instanceName)
		{
			try
			{
				if (!PerformanceCounterCategory.Exists(PerformanceCategoryName))
				{
					InstallCounters();
				}
				else
				{
					_countersInitialized = true;
					//the below seems to have issues upon reinitialization. Just force using the installer.
					////check to see if all of the current counters are installed.
					//PerformanceCounterCategory perfCategory = new PerformanceCounterCategory(ForwardingCounters.PerformanceCategoryName);
					//bool recreate = false;

					//foreach (string counterName in ForwardingCounters.PerformanceCounterNames)
					//{
					//    if (!perfCategory.CounterExists(counterName))
					//    {
					//        LoggingWrapper.Write("Counter " + counterName + " not found in category " + ForwardingCounters.PerformanceCategoryName, "Relay");
					//        recreate = true;
					//        break;
					//    }
					//}
					//if (recreate)
					//{
					//    LoggingWrapper.Write("Recreating performance counter category " + ForwardingCounters.PerformanceCategoryName, "Relay");
					//    RemoveCounters();
					//    InstallCounters();
					//}
					//else
					//{
					//    countersInitialized = true;
					//}
				}
				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
							);
					}

					if (PerformanceCounterCategory.CounterExists(PerformanceCounterNames[(int)PerformanceCounterIndexes.AvgMsgLife], 
						PerformanceCategoryName))
					{
						_avgMessageLife = new AverageMessageLife(
							PerformanceCounters[(int)PerformanceCounterIndexes.AvgMsgLife],
							PerformanceCounters[(int)PerformanceCounterIndexes.AvgMsgLifeBase]);
					}

					if (PerformanceCounterCategory.CounterExists(PerformanceCounterNames[(int)PerformanceCounterIndexes.SaveWithConfirm],
						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 (System.Security.SecurityException)
			{
				if (_log.IsWarnEnabled)
					_log.Warn("Could not automatically install relay forwarding counters. Please run InstallUtil against MySpace.RelayComponent.Forwarding.dll to install counters manually.");
				_countersInitialized = false;
			}
			catch (UnauthorizedAccessException)
			{
				if (_log.IsWarnEnabled)
					_log.Warn("Could not automatically install relay forwarding counters. Please run InstallUtil against MySpace.RelayComponent.Forwarding.dll to install counters manually.");
				_countersInitialized = false;
			}
			catch (Exception ex)
			{
				if (_log.IsErrorEnabled)
					_log.ErrorFormat("Error initializing relay forwarding counters: {0}", ex);
				_countersInitialized = false;
			}
		}