public void WriteLatenciesToTwoBuckets_MeasurementsSeparate_Success()
        {
            _block = TimedLatencyAggregatorBlockFactory.CreateBlock(_outputBuffer,
                                                                    String.Empty,
                                                                    _intervalService,
                                                                    _log.Object);
            var pulseDate = DateTime.Now;

            // Bucket one
            TestUtility.Range(5, false).ForEach(p => _block.Post(new Timing("foo", p * 100)));
            // Bucket two
            TestUtility.Range(5, false).ForEach(p => _block.Post(new Timing("bar", p * 100)));
            _block.WaitUntilAllItemsProcessed();
            _intervalService.Pulse(pulseDate);

            Assert.AreEqual(5, _outputBuffer["foo.count"]);
            Assert.AreEqual(100, _outputBuffer["foo.min"]);
            Assert.AreEqual(500, _outputBuffer["foo.max"]);
            Assert.AreEqual(300, _outputBuffer["foo.mean"]);
            Assert.AreEqual(1500, _outputBuffer["foo.sum"]);

            Assert.AreEqual(5, _outputBuffer["bar.count"]);
            Assert.AreEqual(100, _outputBuffer["bar.min"]);
            Assert.AreEqual(500, _outputBuffer["bar.max"]);
            Assert.AreEqual(300, _outputBuffer["bar.mean"]);
            Assert.AreEqual(1500, _outputBuffer["bar.sum"]);

            Assert.AreEqual(10, _outputBuffer.Items.Count);
        }
Exemplo n.º 2
0
        public void WriteOneLatency_OneMetricFlushed_Success()
        {
            _block = TimedLatencyAggregatorBlockFactory.CreateBlock(_outputBuffer,
                                                                    String.Empty,
                                                                    _intervalService,
                                                                    true,
                                                                    _log.Object);
            var pulseDate = DateTime.Now;

            _block.Post(new Timing("foo.bar.baz", 100));
            _block.WaitUntilAllItemsProcessed();
            _intervalService.Pulse(pulseDate);

            Assert.AreEqual(new GraphiteLine("foo.bar.baz.count", 1, pulseDate.ToEpoch()), _outputBuffer.GetGraphiteLine(0));
            Assert.AreEqual(new GraphiteLine("foo.bar.baz.min", 100, pulseDate.ToEpoch()), _outputBuffer.GetGraphiteLine(1));
            Assert.AreEqual(new GraphiteLine("foo.bar.baz.max", 100, pulseDate.ToEpoch()), _outputBuffer.GetGraphiteLine(2));
            Assert.AreEqual(new GraphiteLine("foo.bar.baz.mean", 100, pulseDate.ToEpoch()), _outputBuffer.GetGraphiteLine(3));
            Assert.AreEqual(new GraphiteLine("foo.bar.baz.sum", 100, pulseDate.ToEpoch()), _outputBuffer.GetGraphiteLine(4));
            Assert.AreEqual(new GraphiteLine("foo.bar.baz.sumSquares", 10000, pulseDate.ToEpoch()), _outputBuffer.GetGraphiteLine(5));
            Assert.AreEqual(6, _outputBuffer.GraphiteLines.Count);
            // Ensure that min, max, mean and sum are all equal
            Assert.IsTrue(_outputBuffer.GetGraphiteLine(1).Quantity == _outputBuffer.GetGraphiteLine(2).Quantity &&
                          _outputBuffer.GetGraphiteLine(2).Quantity == _outputBuffer.GetGraphiteLine(3).Quantity &&
                          _outputBuffer.GetGraphiteLine(3).Quantity == _outputBuffer.GetGraphiteLine(4).Quantity);
        }
        public void WriteTwoLatencies_CalulateMinMaxMeanSum_Success()
        {
            _block = TimedLatencyAggregatorBlockFactory.CreateBlock(_outputBuffer,
                                                                    String.Empty,
                                                                    _intervalService,
                                                                    _log.Object);
            var pulseDate = DateTime.Now;

            _block.Post(new Timing("foo", 5));
            _block.Post(new Timing("foo", 15));
            _block.WaitUntilAllItemsProcessed();
            _intervalService.Pulse(pulseDate);

            Assert.AreEqual(15, _outputBuffer["foo.max"]);
            Assert.AreEqual(5, _outputBuffer["foo.min"]);
            Assert.AreEqual(10, _outputBuffer["foo.mean"]);
            Assert.AreEqual(2, _outputBuffer["foo.count"]);
            Assert.AreEqual(20, _outputBuffer["foo.sum"]);
        }
        public void WriteMinAndMaxLatencies_Success()
        {
            _block = TimedLatencyAggregatorBlockFactory.CreateBlock(_outputBuffer,
                                                                    String.Empty,
                                                                    _intervalService,
                                                                    _log.Object);
            var pulseDate = DateTime.Now;

            _block.Post(new Timing("foo.bar", 100));
            _block.Post(new Timing("foo.bar", 200));
            _block.WaitUntilAllItemsProcessed();
            _intervalService.Pulse(pulseDate);

            Assert.AreEqual(100, _outputBuffer["foo.bar.min"]);
            Assert.AreEqual(200, _outputBuffer["foo.bar.max"]);
            Assert.AreEqual(150, _outputBuffer["foo.bar.mean"]);
            Assert.AreEqual(300, _outputBuffer["foo.bar.sum"]);
            Assert.AreEqual(2, _outputBuffer["foo.bar.count"]);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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());
        }