예제 #1
0
        public async void Should_run()
        {
            //Arrange
            var configBusinessMock = new Mock<IConfigBusiness>(MockBehavior.Strict);
            var config = Mock.Of<IConfig>(x => x.Databases == Mocks.Of<IDatabaseConfig>().Take(1));
            configBusinessMock.Setup(x => x.LoadFiles(It.IsAny<string[]>())).Returns(config);
            var counterBusinessMock = new Mock<ICounterBusiness>(MockBehavior.Strict);
            counterBusinessMock.Setup(x => x.GetPerformanceCounterGroups(config)).Returns(Mocks.Of<IPerformanceCounterGroup>().Take(10).ToList());
            var publisherBusinessMock = new Mock<IPublisherBusiness>(MockBehavior.Strict);
            var influxDbAgentLoaderMock = new Mock<IInfluxDbAgentLoader>(MockBehavior.Strict);
            var influxDbAgentMock = new Mock<IInfluxDbAgent>(MockBehavior.Strict);
            influxDbAgentMock.Setup(x => x.PingAsync()).ReturnsAsync(new Pong());
            influxDbAgentLoaderMock.Setup(x => x.GetAgent(config.Databases.First())).Returns(influxDbAgentMock.Object);
            var sendBusinessMock = new Mock<ISendBusiness>(MockBehavior.Strict);
            var tagLaoderMock = new Mock<ITagLoader>(MockBehavior.Strict);
            var processor = new Processor(configBusinessMock.Object, counterBusinessMock.Object, publisherBusinessMock.Object, sendBusinessMock.Object, tagLaoderMock.Object);
            var configFiles = new string[] { };

            //Act
            await processor.RunAsync(configFiles);

            //Assert
            counterBusinessMock.Verify(x => x.GetPerformanceCounterGroups(config), Times.Once);
            influxDbAgentMock.Verify(x => x.PingAsync(), Times.Once);
        }
예제 #2
0
        public WindowsService()
        {
            _console = new ServerConsole();
            ServiceName = Constants.ServiceName;

            //TODO: This can be removed when the new version of Tharga.Toolkit.Console is used. One version after 1.5.13.0 will do this for you.
            if (!EventLog.SourceExists(ServiceName))
            {
                EventLog.CreateEventSource(ServiceName, "Application");
            }

            //TODO: Inject before this point
            var configBusiness = new ConfigBusiness(new FileLoaderAgent());
            configBusiness.InvalidConfigEvent += InvalidConfigEvent;
            var influxDbAgentLoader = new InfluxDbAgentLoader();
            var counterBusiness = new CounterBusiness();
            counterBusiness.GetPerformanceCounterEvent += GetPerformanceCounterEvent;
            var sendBusiness = new SendBusiness(configBusiness, influxDbAgentLoader);
            sendBusiness.SendBusinessEvent += SendBusinessEvent;
            var tagLoader = new TagLoader(configBusiness);
            _processor = new Processor(configBusiness, counterBusiness, sendBusiness, tagLoader);
            _processor.EngineActionEvent += _processor_EngineActionEvent;

            // These Flags set whether or not to handle that specific
            //  type of event. Set to true if you need it, false otherwise.
            CanHandlePowerEvent = true;
            CanHandleSessionChangeEvent = true;
            CanPauseAndContinue = true;
            CanShutdown = true;
            CanStop = true;
        }
예제 #3
0
        public override async Task<bool> InvokeAsync(string paramList)
        {
            var config = _configBusiness.LoadFiles(new string[] { });
            var counterGroups = _publisherBusiness.GetCounterPublishers(config).ToArray();

            var index = 0;
            var counterPublisher = QueryParam("Counter", GetParam(paramList, index++), counterGroups.Select(x => new KeyValuePair<ICounterPublisher, string>(x, x.CounterName)));

            var processor = new Processor(_configBusiness, _counterBusiness, _publisherBusiness, _sendBusiness, _tagLoader);
            processor.EngineActionEvent += EngineActionEvent;

            //if (counterPublisher == null)
            //{
            //    if (!processor.RunAsync(new string[] { }).Wait(5000))
            //    {
            //        throw new InvalidOperationException("Unable to start processor engine.");
            //    }
            //}
            //else
            //{
                var counterPublishers = new[] { counterPublisher };
                await processor.RunAsync(null, counterPublishers, config.Application.Metadata);
            //}

            return true;
        }
예제 #4
0
        public override async Task<bool> InvokeAsync(string paramList)
        {
            var config = _configBusiness.LoadFiles(new string[] { });
            var counterGroups = _counterBusiness.GetPerformanceCounterGroups(config).ToArray();

            var index = 0;
            var counterGroup = QueryParam("Group", GetParam(paramList, index++), counterGroups.Select(x => new KeyValuePair<IPerformanceCounterGroup, string>(x, x.Name)));

            var processor = new Processor(_configBusiness, _counterBusiness, _publisherBusiness, _sendBusiness, _tagLoader);
            processor.EngineActionEvent += EngineActionEvent;

            if (counterGroup == null)
            {
                if (!processor.RunAsync(new string[] { }).Wait(5000))
                {
                    throw new InvalidOperationException("Unable to start processor engine.");
                }
            }
            else
            {
                var counterGroupsToRead = new[] { counterGroup };
                await processor.RunAsync(counterGroupsToRead, null, config.Application.Metadata);
            }

            return true;
        }
예제 #5
0
        public WindowsService()
        {
            _console = new ServerConsole();
            ServiceName = Constants.ServiceName;

            //TODO: Inject before this point
            var configBusiness = new ConfigBusiness(new FileLoaderAgent());
            configBusiness.InvalidConfigEvent += InvalidConfigEvent;
            var influxDbAgentLoader = new InfluxDbAgentLoader();
            var counterBusiness = new CounterBusiness();
            var publisherBusiness = new PublisherBusiness();
            counterBusiness.GetPerformanceCounterEvent += GetPerformanceCounterEvent;
            CounterBusiness.ChangedCurrentCultureEvent += ChangedCurrentCultureEvent;
            var sendBusiness = new SendBusiness(configBusiness, influxDbAgentLoader);
            sendBusiness.SendBusinessEvent += SendBusinessEvent;
            var tagLoader = new TagLoader(configBusiness);
            _processor = new Processor(configBusiness, counterBusiness, publisherBusiness, sendBusiness, tagLoader);
            _processor.EngineActionEvent += _processor_EngineActionEvent;
            _logger = new MyLogger();

            // These Flags set whether or not to handle that specific
            //  type of event. Set to true if you need it, false otherwise.
            CanHandlePowerEvent = true;
            CanHandleSessionChangeEvent = true;
            CanPauseAndContinue = true;
            CanShutdown = true;
            CanStop = true;

            _console.LineWrittenEvent += _console_LineWrittenEvent;
        }
        public async override Task<bool> InvokeAsync(string paramList)
        {
            var config = _configBusiness.LoadFiles(new string[] { });
            var counterGroups = _counterBusiness.GetPerformanceCounterGroups(config).ToArray();

            var index = 0;
            var counterGroup = QueryParam("Group", GetParam(paramList, index++), counterGroups.Select(x => new KeyValuePair<IPerformanceCounterGroup, string>(x, x.Name)));

            var counterGroupsToRead = counterGroup != null ? new[] { counterGroup } : counterGroups;

            var processor = new Processor(_configBusiness, _counterBusiness, _publisherBusiness, _sendBusiness, _tagLoader);
            processor.EngineActionEvent += EngineActionEvent;

            var count = 0;
            foreach (var cg in counterGroupsToRead)
            {
                count += await processor.CollectAssync(cg, config.Application.Metadata);
            }
            //OutputInformation("Totally {0} metrics points where collected and sent to the database.", count);

            return true;
        }