private Action CreateReportingAction(CounterListenerElement config) { CounterListener listener = new CounterListener(config.Category, config.Instance, config.Counter); IMonitoringChannel channel; if (config.Sampling.HasValue) { channel = this.factory.CreateChannel(config.Type, config.Target, config.Sampling.Value); } else { channel = this.factory.CreateChannel(config.Type, config.Target); } this.counters.Add(listener); return(() => { float?value = listener.ReportValue(); if (value.HasValue) { channel.Report(config.Key, (long)value.Value); } }); }
private Action CreateReportingAction(CounterListenerElement config) { CounterListener listener = new CounterListener(config.Category, config.Instance, config.Counter, _counterFactory); IMonitoringChannel channel; if (config.Sampling.HasValue) { channel = this.factory.CreateChannel(config.Type, config.Target, config.Sampling.Value); } else { channel = this.factory.CreateChannel(config.Type, config.Target); } this.counters.Add(listener); return(() => { float?value = null; try { value = listener.ReportValue(); } catch (InvalidOperationException ex) { Logger.Error(ex, "Failed to report value from counter. It will retry on next interval"); } if (value.HasValue) { channel.Report(config.Key, value.Value); } }); }
private Action CreateReportingAction(CounterListenerElement config) { CounterListener listener = new CounterListener(config.Category, config.Instance, config.Counter); IMonitoringChannel channel; if (config.Sampling.HasValue) { channel = this.factory.CreateChannel(config.Type, config.Target, config.Sampling.Value); } else { channel = this.factory.CreateChannel(config.Type, config.Target); } this.counters.Add(listener); return () => { float? value = listener.ReportValue(); if (value.HasValue) { channel.Report(config.Key, (int)value.Value); } }; }