Ejemplo n.º 1
0
        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>();
        }
Ejemplo n.º 2
0
        public void Start(bool waitForCompletion = true)
        {
            //TODO : JV IS CONFIG FILE A ACTUAL FILE PATH?  IF SO THEN ITS MISLEADING SHOULD BE CONFIGFILEPATH??
            LoggingBootstrap.Configure();

            var configFile = ResolveConfigFile(_configFile);

            if (!File.Exists(configFile))
            {
                throw new FileNotFoundException("Could not find the statsd.net config file. I looked here: " + configFile);
            }
            _config = ConfigurationFactory.Parse(configFile);
            _statsd = new Statsd(_config);
            if (waitForCompletion)
            {
                _statsd.ShutdownWaitHandle.WaitOne();
            }
        }