示例#1
0
 public void Initialise()
 {
     _intervalService = new ControllableIntervalService();
     _outputBuffer    = new BucketOutputBlock();
     _block           = TimedGaugeAggregatorBlockFactory.CreateBlock(_outputBuffer,
                                                                     String.Empty,
                                                                     false,
                                                                     _intervalService);
 }
 public void Initialise()
 {
     _intervalService = new ControllableIntervalService();
     _outputBuffer    = new GraphiteLineOutputBlock();
     _log             = new Mock <ILog>();
     _block           = TimedGaugeAggregatorBlockFactory.CreateBlock(_outputBuffer,
                                                                     String.Empty,
                                                                     false,
                                                                     _intervalService,
                                                                     _log.Object);
 }
示例#3
0
        private void LoadAggregators(StatsdnetConfiguration config,
                                     IntervalService intervalService,
                                     BroadcastBlock <Bucket> messageBroadcaster,
                                     ISystemMetricsService systemMetrics)
        {
            foreach (var aggregator in config.Aggregators)
            {
                switch (aggregator.Key)
                {
                case "counters":
                    var counter = aggregator.Value as CounterAggregationConfig;
                    AddAggregator(MessageType.Counter,
                                  TimedCounterAggregatorBlockFactory.CreateBlock(messageBroadcaster,
                                                                                 counter.Namespace,
                                                                                 intervalService),
                                  systemMetrics);
                    break;

                case "gauges":
                    var gauge = aggregator.Value as GaugeAggregatorConfig;
                    AddAggregator(MessageType.Gauge,
                                  TimedGaugeAggregatorBlockFactory.CreateBlock(messageBroadcaster,
                                                                               gauge.Namespace,
                                                                               gauge.RemoveZeroGauges,
                                                                               intervalService),
                                  systemMetrics);
                    break;

                case "calendargrams":
                    var calendargram = aggregator.Value as CalendargramAggregationConfig;
                    AddAggregator(MessageType.Calendargram,
                                  TimedCalendargramAggregatorBlockFactory.CreateBlock(messageBroadcaster,
                                                                                      calendargram.Namespace,
                                                                                      intervalService,
                                                                                      new TimeWindowService()),
                                  systemMetrics);
                    break;

                case "timers":
                    var timer = aggregator.Value as TimersAggregationConfig;
                    AddAggregator(MessageType.Timing,
                                  TimedLatencyAggregatorBlockFactory.CreateBlock(messageBroadcaster,
                                                                                 timer.Namespace,
                                                                                 intervalService,
                                                                                 timer.CalculateSumSquares),
                                  systemMetrics);
                    // Add Percentiles
                    foreach (var percentile in timer.Percentiles)
                    {
                        AddAggregator(MessageType.Timing,
                                      TimedLatencyPercentileAggregatorBlockFactory.CreateBlock(messageBroadcaster,
                                                                                               timer.Namespace,
                                                                                               intervalService,
                                                                                               percentile.Threshold,
                                                                                               percentile.Name),
                                      systemMetrics);
                    }
                    break;
                }
            }
            // Add the Raw (pass-through) aggregator
            AddAggregator(MessageType.Raw,
                          PassThroughBlockFactory.CreateBlock(messageBroadcaster, intervalService),
                          systemMetrics);
        }
示例#4
0
        public Statsd(dynamic config)
            : this((string)config.general.name)
        {
            _log.Info("statsd.net loading config.");
            var systemMetrics = SuperCheapIOC.Resolve <ISystemMetricsService>();

            // Load backends
            if (config.backends.console.enabled)
            {
                AddBackend(new ConsoleBackend(), "console");
            }
            if (config.backends.graphite.enabled)
            {
                AddBackend(new GraphiteBackend(config.backends.graphite.host, (int)config.backends.graphite.port, systemMetrics), "graphite");
            }
            if (config.backends.sqlserver.enabled)
            {
                AddBackend(new SqlServerBackend(
                               config.backends.sqlserver.connectionString,
                               config.general.name,
                               systemMetrics,
                               batchSize: (int)config.backends.sqlserver.writeBatchSize),
                           "sqlserver");
            }

            // Load Aggregators
            var intervalServices = new List <IIntervalService>();
            var intervalService  = new IntervalService(( int )config.calc.flushIntervalSeconds);

            intervalServices.Add(intervalService);
            AddAggregator(MessageType.Counter,
                          TimedCounterAggregatorBlockFactory.CreateBlock(_messageBroadcaster, config.calc.countersNamespace, intervalService, _log));
            AddAggregator(MessageType.Gauge,
                          TimedGaugeAggregatorBlockFactory.CreateBlock(_messageBroadcaster, config.calc.gaugesNamespace, config.calc.deleteGaugesOnFlush, intervalService, _log));
            AddAggregator(MessageType.Set,
                          TimedSetAggregatorBlockFactory.CreateBlock(_messageBroadcaster, config.calc.setsNamespace, intervalService, _log));
            AddAggregator(MessageType.Timing,
                          TimedLatencyAggregatorBlockFactory.CreateBlock(_messageBroadcaster, config.calc.timersNamespace, intervalService, _log));

            // Load Latency Percentile Aggregators
            foreach (var percentile in (IDictionary <string, object>)config.calc.percentiles)
            {
                dynamic thePercentile = percentile.Value;
                intervalService = new IntervalService((int)thePercentile.flushIntervalSeconds);
                AddAggregator(MessageType.Timing,
                              TimedLatencyPercentileAggregatorBlockFactory.CreateBlock(_messageBroadcaster, config.calc.timersNamespace,
                                                                                       intervalService,
                                                                                       (int)thePercentile.percentile,
                                                                                       percentile.Key,
                                                                                       _log));
                intervalServices.Add(intervalService);
            }

            // Load listeners - done last and once the rest of the chain is in place
            if (config.listeners.udp.enabled)
            {
                AddListener(new UdpStatsListener((int)config.listeners.udp.port, systemMetrics));
            }
            if (config.listeners.tcp.enabled)
            {
                AddListener(new TcpStatsListener((int)config.listeners.tcp.port, systemMetrics));
            }
            if (config.listeners.http.enabled)
            {
                AddListener(new HttpStatsListener((int)config.listeners.http.port, systemMetrics));
            }

            // Now start the interval service
            intervalServices.ForEach(p => p.Start());
        }