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"); }
public SqlServerBackend(string connectionString, string collectorName, ISystemMetricsService systemMetrics, int retries = 3, int batchSize = 50) { _log = SuperCheapIOC.Resolve <ILog>(); _connectionString = connectionString; _collectorName = collectorName; _systemMetrics = systemMetrics; _retries = retries; InitialiseRetryHandling(); _batchBlock = new BatchBlock <GraphiteLine>(batchSize); _actionBlock = new ActionBlock <GraphiteLine[]>(p => SendToDB(p), new ExecutionDataflowBlockOptions() { MaxDegreeOfParallelism = 1 }); _batchBlock.LinkTo(_actionBlock); _batchBlock.Completion.ContinueWith(p => _actionBlock.Complete()); _actionBlock.Completion.ContinueWith(p => { _isActive = false; }); _completionTask = new Task(() => { _log.Info("SqlServerBackend - Completion has been signaled. Waiting for action block to complete."); _batchBlock.Complete(); _actionBlock.Completion.Wait(); }); }
public void Configure(string collectorName, XElement configElement, ISystemMetricsService systemMetrics) { _log = SuperCheapIOC.Resolve <ILog>(); _systemMetrics = systemMetrics; var config = new SqlServerConfiguration(configElement.Attribute("connectionString").Value, configElement.ToInt("writeBatchSize")); _connectionString = config.ConnectionString; _collectorName = collectorName; _retries = config.Retries; InitialiseRetryHandling(); _batchBlock = new BatchBlock <GraphiteLine>(config.WriteBatchSize); _actionBlock = new ActionBlock <GraphiteLine[]>(p => SendToDB(p), new ExecutionDataflowBlockOptions() { MaxDegreeOfParallelism = 1 }); _batchBlock.LinkTo(_actionBlock); _batchBlock.Completion.ContinueWith(p => _actionBlock.Complete()); _actionBlock.Completion.ContinueWith(p => { _isActive = false; }); _completionTask = new Task(() => { _log.Info("SqlServerBackend - Completion has been signaled. Waiting for action block to complete."); _batchBlock.Complete(); _actionBlock.Completion.Wait(); }); }
public GraphiteBackend(string host, int port, ISystemMetricsService systemMetrics) { _log = SuperCheapIOC.Resolve <ILog>(); var ipAddress = Utility.HostToIPv4Address(host); _client = new UdpClient(); _client.Connect(ipAddress, port); _systemMetrics = systemMetrics; _completionTask = new Task(() => { _isActive = false; }); }
public StatsdnetForwardingClient(string host, int port, ISystemMetricsService systemMetrics, int numRetries = 1, bool enableCompression = true) { _host = host; _port = port; _systemMetrics = systemMetrics; _numRetries = numRetries; _enableCompression = enableCompression; _client = new TcpClient(); _log = SuperCheapIOC.Resolve <ILog>(); }
public StatsdnetTcpListener(int port, ISystemMetricsService systemMetrics) { _systemMetrics = systemMetrics; _log = SuperCheapIOC.Resolve <ILog>(); IsListening = false; _activeConnections = 0; _tcpListener = new TcpListener(IPAddress.Any, port); _decoderBlock = new ActionBlock <DecoderBlockPacket>((data) => { DecodePacketAndForward(data); }, Utility.UnboundedExecution()); }
public void Configure(string collectorName, XElement configElement, ISystemMetricsService systemMetrics) { _log = SuperCheapIOC.Resolve <ILog>(); _systemMetrics = systemMetrics; _completionTask = new Task(() => { _isActive = false; }); _batchBlock = new BatchBlock <GraphiteLine>(BATCH_SIZE); _senderBlock = new ActionBlock <GraphiteLine[]>((batch) => SendBatch(batch), Utility.OneAtATimeExecution()); _batchBlock.LinkTo(_senderBlock); _isActive = true; _host = configElement.Attribute("host").Value; _port = configElement.ToInt("port"); }
public Statsd(string serviceName = null) { LoggingBootstrap.Configure(); _log.Info("statsd.net starting."); _tokenSource = new CancellationTokenSource(); _shutdownComplete = new ManualResetEvent(false); SuperCheapIOC.Add(_log); var systemInfoService = new SystemInfoService(); SuperCheapIOC.Add(systemInfoService as ISystemInfoService); serviceName = serviceName ?? systemInfoService.HostName; var systemMetricsService = new SystemMetricsService("statsdnet", serviceName); SuperCheapIOC.Add(systemMetricsService as ISystemMetricsService); /** * The flow is: * Listeners -> * Message Parser -> * router -> * Aggregator -> * Broadcaster -> * Backends */ // Initialise the core blocks _router = new StatsdMessageRouterBlock(); _messageParser = MessageParserBlockFactory.CreateMessageParserBlock(_tokenSource.Token, SuperCheapIOC.Resolve <ISystemMetricsService>(), _log); _messageParser.LinkTo(_router); _messageParser.Completion.LogAndContinueWith(_log, "MessageParser", () => { _log.Info("MessageParser: Completion signaled. Notifying the MessageBroadcaster."); _messageBroadcaster.Complete(); }); _messageBroadcaster = new BroadcastBlock <GraphiteLine>(GraphiteLine.Clone); _messageBroadcaster.Completion.LogAndContinueWith(_log, "MessageBroadcaster", () => { _log.Info("MessageBroadcaster: Completion signaled. Notifying all backends."); _backends.ForEach(q => q.Complete()); }); // Add the broadcaster to the IOC container SuperCheapIOC.Add <BroadcastBlock <GraphiteLine> >(_messageBroadcaster); systemMetricsService.SetTarget(_messageBroadcaster); _backends = new List <IBackend>(); _listeners = new List <IListener>(); }
public void Configure(string collectorName, XElement configElement, ISystemMetricsService systemMetrics) { _log = SuperCheapIOC.Resolve <ILog>(); _systemMetrics = systemMetrics; _completionTask = new Task(() => { _isActive = false; }); _senderBlock = new ActionBlock <GraphiteLine>((message) => SendLine(message), Utility.UnboundedExecution()); _isActive = true; var config = new GraphiteConfiguration(configElement.Attribute("host").Value, configElement.ToInt("port")); var ipAddress = Utility.HostToIPv4Address(config.Host); _client = new UdpClient(); _client.Connect(ipAddress, config.Port); }
public SignalFxReporter(string baseURI, string apiToken, TimeSpan timeout, IWebRequestorFactory requestor = null) { _log = SuperCheapIOC.Resolve <ILog>(); if (requestor == null) { requestor = new WebRequestorFactory() .WithUri(baseURI + "/v2/datapoint") .WithMethod("POST") .WithContentType("application/x-protobuf") .WithHeader("X-SF-TOKEN", apiToken) .WithTimeout(timeout); } this._requestor = requestor; this._apiToken = apiToken; }
public void Configure(string collectorName, XElement configElement, ISystemMetricsService systemMetrics) { _completionTask = new Task(() => IsActive = false); _log = SuperCheapIOC.Resolve <ILog>(); _config = parseConfig(configElement); _reporter = new SignalFxReporter(_config.BaseURI, _config.ApiToken, _config.PostTimeout); _processBlock = new ActionBlock <Bucket>(bucket => ProcessBucket(bucket), Utility.UnboundedExecution()); _batchBlock = new BatchBlock <TypeDatapoint>(_config.MaxBatchSize); _outputBlock = new ActionBlock <TypeDatapoint[]>(datapoint => ProcessDatapoints(datapoint), Utility.OneAtATimeExecution()); _batchBlock.LinkTo(_outputBlock); _triggerBatchTimer = new Timer((state) => trigger(state), null, TimeSpan.FromSeconds(1), _config.MaxTimeBetweenBatches); IsActive = true; }
public void Configure(string collectorName, XElement configElement, ISystemMetricsService systemMetrics) { _completionTask = new Task(() => IsActive = false); _log = SuperCheapIOC.Resolve <ILog>(); _systemMetrics = systemMetrics; var config = new LibratoBackendConfiguration( email: configElement.Attribute("email").Value, token: configElement.Attribute("token").Value, numRetries: configElement.ToInt("numRetries"), retryDelay: Utility.ConvertToTimespan(configElement.Attribute("retryDelay").Value), postTimeout: Utility.ConvertToTimespan(configElement.Attribute("postTimeout").Value), maxBatchSize: configElement.ToInt("maxBatchSize"), countersAsGauges: configElement.ToBoolean("countersAsGauges") ); _config = config; _source = collectorName; _serviceVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(); _preprocessorBlock = new ActionBlock <Bucket>(bucket => ProcessBucket(bucket), Utility.UnboundedExecution()); _batchBlock = new BatchBlock <LibratoMetric>(_config.MaxBatchSize); _outputBlock = new ActionBlock <LibratoMetric[]>(lines => PostToLibrato(lines), Utility.OneAtATimeExecution()); _batchBlock.LinkTo(_outputBlock); _client = new RestClient(LIBRATO_API_URL); _client.Authenticator = new HttpBasicAuthenticator(_config.Email, _config.Token); _client.Timeout = (int)_config.PostTimeout.TotalMilliseconds; _retryPolicy = new RetryPolicy <LibratoErrorDetectionStrategy>(_config.NumRetries); _retryPolicy.Retrying += (sender, args) => { _log.Warn(String.Format("Retry {0} failed. Trying again. Delay {1}, Error: {2}", args.CurrentRetryCount, args.Delay, args.LastException.Message), args.LastException); _systemMetrics.LogCount("backends.librato.retry"); }; _retryStrategy = new Incremental(_config.NumRetries, _config.RetryDelay, TimeSpan.FromSeconds(2)); IsActive = true; }
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()); }