Example #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;
            }
        }
Example #2
0
        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;
            }
        }