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;
        }
        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 CompositeRoot()
 {
     ClientConsole = new ClientConsole();
     InfluxDbAgentLoader = new InfluxDbAgentLoader();
     FileLoaderAgent = new FileLoaderAgent();
     ConfigBusiness = new ConfigBusiness(FileLoaderAgent);
     ConfigBusiness.InvalidConfigEvent += InvalidConfigEvent;
     CounterBusiness = new CounterBusiness();
     SendBusiness = new SendBusiness(ConfigBusiness, InfluxDbAgentLoader);
     SendBusiness.SendBusinessEvent += SendBusinessEvent;
     TagLoader = new TagLoader(ConfigBusiness);
 }
        public void Should_return_a_result()
        {
            //Arrange
            var counterBusiness = new CounterBusiness();
            var config = Mock.Of<IConfig>(x => x.Groups == Mocks.Of<ICounterGroup>(y => y.Name == "A" && y.SecondsInterval == 10 && y.Counters == Mocks.Of<ICounter>(z => z.CategoryName == "Processor" && z.CounterName == "% Processor Time" && z.InstanceName == "_Total").Take(2).ToList()).Take(2).ToList());
            Exception exception = null;

            //Act
            var result = counterBusiness.GetPerformanceCounterGroups(config);

            //Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(exception, Is.Null);
            Assert.That(result.Count(), Is.EqualTo(2));
        }
Exemple #5
0
        public void Should_Apply_Filter_Which_Returns_None()
        {
            // The test filter remove all counters

            // Arrange
            var filterMock = new Mock<ICounterInstanceFilter>();
            filterMock.Setup(x => x.Execute("MyInstance")).Returns((string)null);
            var filters = new[] { filterMock.Object };
            var counters = Mocks.Of<ICounter>(c => c.CategoryName == "Processor" && c.CounterName == "% Processor Time" && c.InstanceName == "*").Take(1).ToList();
            var counterGroup = Mocks.Of<ICounterGroup>(cg => cg.Name == "A" && cg.Counters == counters && cg.Filters == filters).Take(1).ToList();
            var config = Mock.Of<IConfig>(cfg => cfg.Groups == counterGroup);
            var counterBusiness = new CounterBusiness();

            // Act
            var result = counterBusiness.GetPerformanceCounterGroups(config);

            // Assert
            Assert.That(result.Count(), Is.EqualTo(1));
            var resultCounters = result.First().GetCounters();
            Assert.That(resultCounters.Count(), Is.EqualTo(0), "Filter should have removed all performances counters");
        }
Exemple #6
0
        public void Should_Apply_Filter_Which_Returns_All()
        {
            // The test filter match all counters
            // For the processor time, it will result in having Environment.ProcessorCount + 1 counters (_Total)

            // Arrange
            var filterExpression = new Func<string, string>(z => z);
            var filterMock = new Mock<ICounterInstanceFilter>();
            filterMock.Setup(x => x.Execute(It.IsAny<string>())).Returns(filterExpression);
            var filters = new[] { filterMock.Object };
            var counters = Mocks.Of<ICounter>(z => z.CategoryName == "Processor" && z.CounterName == "% Processor Time" && z.InstanceName == "*" && z.MachineName == null && z.Max == null && z.Tags == new List<ITag> {}).Take(1).ToList();
            var counterGroup = Mocks.Of<ICounterGroup>(y => y.Name == "A" && y.SecondsInterval == 10 && y.Counters == counters && y.Filters == filters).Take(1).ToList();
            var config = Mock.Of<IConfig>(x => x.Groups == counterGroup);
            var counterBusiness = new CounterBusiness();

            // Act
            var result = counterBusiness.GetPerformanceCounterGroups(config);

            // Assert
            Assert.That(result.Count(), Is.EqualTo(1));
            var resultCounters = result.First().GetCounters();
            Assert.That(resultCounters.Count(), Is.EqualTo(Environment.ProcessorCount + 1));
        }
Exemple #7
0
        public void Should_Apply_Filter_Which_Returns_One()
        {
            // The test filter match one counter : _Total 

            // Arrange
            var filterExpression = new Func<string, string>(z => z == "_Total" ? z : null);
            var filterMock = new Mock<ICounterInstanceFilter>();
            filterMock.Setup(x => x.Execute(It.IsAny<string>())).Returns(filterExpression);
            var filters = new[] { filterMock.Object };
            var counters = Mocks.Of<ICounter>(z => z.CategoryName == "Processor" && z.CounterName == "% Processor Time" && z.InstanceName == "*").Take(1).ToList();
            var counterGroup = Mocks.Of<ICounterGroup>(y => y.Name == "A" && y.SecondsInterval == 10 && y.Counters == counters && y.Filters == filters).Take(1).ToList();
            var config = Mock.Of<IConfig>(x => x.Groups == counterGroup);
            var counterBusiness = new CounterBusiness();

            // Act
            var result = counterBusiness.GetPerformanceCounterGroups(config);

            // Assert
            Assert.That(result.Count(), Is.EqualTo(1));
            var resultCounters = result.First().GetCounters();
            Assert.That(resultCounters.Count(), Is.EqualTo(1));
            Assert.AreEqual(resultCounters.First().InstanceName, "_Total");
        }
        public void Should_throw_if_no_groups()
        {
            //Arrange
            var counterBusiness = new CounterBusiness();
            var config = Mock.Of<IConfig>();
            Exception exception = null;
            List<IPerformanceCounterGroup> result = null;

            //Act
            try
            {
                result = counterBusiness.GetPerformanceCounterGroups(config).ToList();
            }
            catch (Exception exp)
            {
                exception = exp;
            }

            //Assert
            Assert.That(result, Is.Null);
            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.Message, Is.EqualTo("No groups in config."));
        }