Exemplo n.º 1
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;
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 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;
        }