public static void StartCollection()
        {
            if (_started)
                return;
            _started = true;

            conf = Config.CarbonatorSection.Current;
            if (conf == null)
            {
                if (conf.LogLevel >= 3)
                    EventLog.WriteEntry(Program.EVENT_SOURCE, "Carbonator configuration is missing. This service cannot start", EventLogEntryType.Error);
                throw new InvalidOperationException("Carbonator configuration is missing. This service cannot start");
            }

            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(conf.DefaultCulture);
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(conf.DefaultCulture);

            if (Config.CarbonatorSection.Current.MaxMetricBufferSize > 0)
            {
                _metricsList = new BlockingCollection<CollectedMetric>(Config.CarbonatorSection.Current.MaxMetricBufferSize);
            }
            else
            {
                _metricsList = new BlockingCollection<CollectedMetric>();
            }

            // start collection and reporting timers
            _metricCollectorTimer = new Timer(collectMetrics, new StateControl(), conf.CollectionInterval, conf.CollectionInterval);
            _metricReporterTimer = new Timer(reportMetrics, new StateControl(), conf.ReportingInterval, conf.ReportingInterval);

            if (conf.LogLevel >= 1)
                EventLog.WriteEntry(Program.EVENT_SOURCE, "Carbonator service has been initialized and began reporting metrics", EventLogEntryType.Information);
        }
Beispiel #2
0
        public static void StartCollection()
        {
            if (_started)
            {
                return;
            }
            _started = true;

            conf = Config.CarbonatorSection.Current;
            if (conf == null)
            {
                Log.Fatal("[StartCollection] Carbonator configuration is missing. This service cannot start");
                throw new InvalidOperationException("Carbonator configuration is missing. This service cannot start");
            }

            Thread.CurrentThread.CurrentCulture   = CultureInfo.GetCultureInfo(conf.DefaultCulture);
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(conf.DefaultCulture);

            if (Config.CarbonatorSection.Current.MaxMetricBufferSize > 0)
            {
                _metricsList = new BlockingCollection <CollectedMetric>(Config.CarbonatorSection.Current.MaxMetricBufferSize);
            }
            else
            {
                _metricsList = new BlockingCollection <CollectedMetric>();
            }

            // load counter watchers that will actually collect metrics for us
            foreach (Config.PerformanceCounterElement counterConfig in Config.CarbonatorSection.Current.Counters)
            {
                CounterWatcher watcher = new CounterWatcher(counterConfig);
                try
                {
                    watcher.Initialize();
                }
                catch (Exception any)
                {
                    Log.Error("[StartCollection] Failed to initialize performance counter watcher for path '{0}'; this configuration element will be skipped: {1} (inner: {2})", counterConfig.Path, any.Message, any.InnerException != null ? any.InnerException.Message : "(null)");
                    continue;
                }
                _watchers.Add(watcher);
            }

            // start collection and reporting timers
            _metricCollectorTimer = new Timer(collectMetrics, new StateControl(), conf.CollectionInterval, conf.CollectionInterval);
            _metricReporterTimer  = new Timer(reportMetrics, new StateControl(), conf.ReportingInterval, conf.ReportingInterval);

            Log.Info("[StartCollection] Carbonator service loaded {0} watchers", _watchers.Count);
        }
Beispiel #3
0
        public static void StartCollection()
        {
            if (_started)
            {
                return;
            }
            _started = true;

            conf = Config.CarbonatorSection.Current;
            if (conf == null)
            {
                if (conf.LogLevel >= 3)
                {
                    EventLog.WriteEntry(Program.EVENT_SOURCE, "Carbonator configuration is missing. This service cannot start", EventLogEntryType.Error);
                }
                throw new InvalidOperationException("Carbonator configuration is missing. This service cannot start");
            }

            Thread.CurrentThread.CurrentCulture   = CultureInfo.GetCultureInfo(conf.DefaultCulture);
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(conf.DefaultCulture);

            if (Config.CarbonatorSection.Current.MaxMetricBufferSize > 0)
            {
                _metricsList = new BlockingCollection <CollectedMetric>(Config.CarbonatorSection.Current.MaxMetricBufferSize);
            }
            else
            {
                _metricsList = new BlockingCollection <CollectedMetric>();
            }

            // start collection and reporting timers
            _metricCollectorTimer = new Timer(collectMetrics, new StateControl(), conf.CollectionInterval, conf.CollectionInterval);
            _metricReporterTimer  = new Timer(reportMetrics, new StateControl(), conf.ReportingInterval, conf.ReportingInterval);

            if (conf.LogLevel >= 1)
            {
                EventLog.WriteEntry(Program.EVENT_SOURCE, "Carbonator service has been initialized and began reporting metrics", EventLogEntryType.Information);
            }
        }