public AppPoolListener(string appPoolName, string category, string counter, CounterInstanceNameCache counterInstanceNameCache, PerformanceCounterFactory counterFactory) { this.appPoolName = appPoolName; this.category = category; this.counter = counter; _counterInstanceNameCache = counterInstanceNameCache; _counterFactory = counterFactory; this.LoadCounterInstanceName(); }
public Kernel(IConfigurationContainer configuration, GraphiteSystemConfiguration systemConfiguration) { _counterInstanceNameCache = new CounterInstanceNameCache(new WmiCounterInstanceNameProvider()) { Expiration = TimeSpan.FromSeconds(systemConfiguration.SystemSettings.InstanceNameCacheExpiration) }; _appPoolListenerRefreshInterval = systemConfiguration.SystemSettings.AppPoolListenerRefreshInterval; this.factory = new ChannelFactory(configuration.Graphite, configuration.StatsD); foreach (var listener in systemConfiguration.EventlogListeners.Cast <EventlogListenerElement>()) { this.CreateEventlogListener(listener); } this.scheduler = new Scheduler(); foreach (var listener in systemConfiguration.CounterListeners.Cast <CounterListenerElement>()) { Action action; try { action = this.CreateReportingAction(listener); this.scheduler.Add(action, listener.Interval); } catch (InvalidOperationException ex) { Logger.Error(ex, "Failed to create CounterListener for: {0} {1} {2}, interval {3}", listener.Category, listener.Counter, listener.Instance, listener.Interval); if (!listener.Retry) { throw; } this.retryCreation.Add(listener); } } if (this.retryCreation.Any()) { this.scheduler.Add(this.RetryCounterCreation, RetryInterval); } foreach (var appPool in systemConfiguration.AppPool.Cast <AppPoolElement>()) { try { AppPoolListener element; var action = this.CreateReportingAction(appPool, out element); this.scheduler.Add(action, appPool.Interval); this.scheduler.Add(() => element.LoadCounterInstanceName(), _appPoolListenerRefreshInterval); } catch (Exception ex) { throw new Exception(string.Format("Failed to create appPoolListerner for: {0}, counter: {1} {2}", appPool.AppPoolName, appPool.Category, appPool.Counter), ex); } } this.scheduler.Start(); }