Example #1
0
        public MSSQLRelayListener(string connectionString, 
            TimeSpan pollInterval,
            CancellationToken cancellationToken,
            int batchSize,
            bool deleteAfterSend,
            ISystemMetricsService metrics)
        {
            _connectionString = connectionString;
            _intervalService = new IntervalService(pollInterval, cancellationToken);
            _cancellationToken = cancellationToken;
            _batchSize = batchSize;
            _deleteAfterSend = deleteAfterSend;
            _metrics = metrics;

            var stopwatch = new Stopwatch();

            _intervalService.Elapsed += (sender, e) =>
                {
                    if (IsListening)
                    {
                        _intervalService.Cancel(true);
                        stopwatch.Restart();
                        ReadAndFeed();
                        stopwatch.Stop();
                        metrics.LogCount("listeners.mssql-relay.feedTimeSeconds", Convert.ToInt32(stopwatch.Elapsed.TotalSeconds));

                        // Only continue the interval service if cancellation
                        // isn't in progress
                        if (!cancellationToken.IsCancellationRequested)
                        {
                            _intervalService.Start();
                        }
                    }
                };
        }
 public SystemMetricsService(string serviceName, string prefix = null, IIntervalService intervalService = null)
 {
     if (intervalService == null)
     {
         intervalService = new IntervalService(10);
     }
     _prefix  = serviceName + "." + (String.IsNullOrEmpty(prefix) ? String.Empty : (prefix + "."));
     _metrics = new ConcurrentDictionary <string, int>();
     intervalService.Elapsed += SendMetrics;
     intervalService.Start();
 }
Example #3
0
 public SystemMetricsService(string serviceName, string prefix = null, IIntervalService intervalService = null, bool hideSystemStats = false)
 {
     if (intervalService == null)
     {
         intervalService = new IntervalService(10);
     }
     _prefix                  = serviceName + "." + (String.IsNullOrEmpty(prefix) ? String.Empty : (prefix + "."));
     _metrics                 = new ConcurrentDictionary <MetricInfo, double>();
     HideSystemStats          = hideSystemStats;
     intervalService.Elapsed += SendMetrics;
     intervalService.Start();
 }
  public SystemMetricsService(string serviceName, string prefix = null, IIntervalService intervalService = null, bool hideSystemStats = false)
  {
    if (intervalService == null)
    {
      intervalService = new IntervalService(10);
    }
    _prefix = serviceName + "." + (String.IsNullOrEmpty(prefix) ? String.Empty : (prefix + "."));
    _metrics = new ConcurrentDictionary<string, double>();
    HideSystemStats = hideSystemStats;
    intervalService.Elapsed += SendMetrics;
    intervalService.Start();
 }
Example #5
0
        public Statsd(StatsdnetConfiguration config)
            : this(config.Name)
        {
            _log.Info("statsd.net loading config.");
            var systemMetrics = SuperCheapIOC.Resolve<ISystemMetricsService>();
            systemMetrics.HideSystemStats = config.HideSystemStats;

            LoadBackends(config, systemMetrics);

            // Load Aggregators
            var intervalServices = new List<IIntervalService>();
            var intervalService = new IntervalService(config.FlushInterval,
              _tokenSource.Token);
            intervalServices.Add(intervalService);
            LoadAggregators(config,
              intervalService,
              _messageBroadcaster,
              systemMetrics);
            // Load Listeners
            LoadListeners(config, _tokenSource.Token, systemMetrics);

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

            // Announce that we've started
            systemMetrics.LogCount("started");
        }
Example #6
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,
                            _log),
                          systemMetrics);
                        break;
                    case "gauges":
                        var gauge = aggregator.Value as GaugeAggregatorConfig;
                        AddAggregator(MessageType.Gauge,
                          TimedGaugeAggregatorBlockFactory.CreateBlock(messageBroadcaster,
                            gauge.Namespace,
                            gauge.RemoveZeroGauges,
                            intervalService,
                            _log),
                          systemMetrics);
                        break;
                    case "calendargrams":
                        var calendargram = aggregator.Value as CalendargramAggregationConfig;
                        AddAggregator(MessageType.Calendargram,
                            TimedCalendargramAggregatorBlockFactory.CreateBlock(messageBroadcaster,
                                calendargram.Namespace,
                                intervalService,
                                new TimeWindowService(),
                                _log),
                                systemMetrics);
                        break;
                    case "timers":
                        var timer = aggregator.Value as TimersAggregationConfig;
                        AddAggregator(MessageType.Timing,
                          TimedLatencyAggregatorBlockFactory.CreateBlock(messageBroadcaster,
                            timer.Namespace,
                            intervalService,
                            timer.CalculateSumSquares,
                            _log),
                          systemMetrics);
                        // Add Percentiles
                        foreach (var percentile in timer.Percentiles)
                        {
                            AddAggregator(MessageType.Timing,
                              TimedLatencyPercentileAggregatorBlockFactory.CreateBlock(messageBroadcaster,
                                timer.Namespace,
                                intervalService,
                                percentile.Threshold,
                                percentile.Name,
                                _log),
                              systemMetrics);
                        }
                        break;

                }
            }
            // Add the Raw (pass-through) aggregator
            AddAggregator(MessageType.Raw,
              PassThroughBlockFactory.CreateBlock(messageBroadcaster, intervalService),
              systemMetrics);
        }