Ejemplo n.º 1
0
        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);
                }
            });
        }
Ejemplo n.º 2
0
        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);
                }
            });
        }
Ejemplo n.º 3
0
        private static void Print(CounterListenerElement listener)
        {
            try
            {
                var counter = new PerformanceCounter(listener.Category, listener.Counter, listener.Instance, true);

                Console.WriteLine(
                    @"{0,-50}{1,-30}",
                    string.Format(@"{0}({1})\{2}", listener.Category, listener.Instance, listener.Counter),
                    counter.CounterType);
            }
            catch (InvalidOperationException exception)
            {
                Console.WriteLine(
                    "ERROR: "
                    + exception.Message
                    + string.Format(" (Category: '{0}', Counter: '{1}', Instance: '{2}')", listener.Category, listener.Counter, listener.Instance));
            }
        }