public void when_there_is_an_existing_base_configuration_then_the_resulting_config_is_combined()
        {
            File.WriteAllText(ConfigurationResolver.BaseSpectatorConfigFile, @"{
                      ""statsdHost"": ""basehost"",
                      ""statsdPort"": 8125,
                      ""metricPrefix"": ""base.prefix"",
                      ""interval"":  ""00:00:01"",
                      ""metrics"": [
                        {
                          ""source"": ""performanceCounter"",
                          ""path"": ""\\Processor(_Total)\\Interrupts/sec"",
                          ""type"": ""gauge"",
                          ""template"": ""base.performance.counter""
                        },
                        {
                          ""source"": ""performanceCounter"",
                          ""path"": ""\\Processor(_Total)\\Interrupts/sec"",
                          ""type"": ""gauge"",
                          ""template"": ""overriden.performance.counter""
                        }
                      ]
                    }", Encoding.UTF8);

            var resolver = new ConfigurationResolver();
            var configuration = resolver.Resolve();

            Assert.That(configuration, Is.TypeOf<ExpiringConfigurationDecorator>());

            var expiringConfig = (ExpiringConfigurationDecorator)configuration;
            var innerConfiguration = expiringConfig.InnerConfiguration;
            Assert.That(innerConfiguration, Is.TypeOf<CombinedSpectatorConfiguration>());
        }
        public void when_there_is_no_base_configuration_then_the_resulting_config_is_not_combined()
        {
            var resolver = new ConfigurationResolver();
            var configuration = resolver.Resolve();

            Assert.That(configuration, Is.Not.TypeOf<CombinedSpectatorConfiguration>());
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

            var configurationResolver = new ConfigurationResolver();

            Log.Info("Starting spectator topshelf host");

            HostFactory.Run(hostConfigurator =>
            {
                hostConfigurator.Service<SpectatorService>(serviceConfigurator =>
                    {
                        var configuration = configurationResolver.Resolve();
                        serviceConfigurator.ConstructUsing(() =>
                            new SpectatorService(
                                configuration,
                                new QueryableSourceFactory(),
                                new StatsdPublisher(
                                        new Statsd(
                                                new StatsdUDP(
                                                    configuration.StatsdHost,
                                                    configuration.StatsdPort
                                                )
                                        )
                                ),
                                new MetricFormatter()
                            )
                        );
                        serviceConfigurator.WhenStarted(myService => myService.Start());
                        serviceConfigurator.WhenStopped(myService => myService.Stop());
                    });

                hostConfigurator.RunAsLocalSystem();

                hostConfigurator.SetDisplayName(@"Spectator Agent");
                hostConfigurator.SetDescription(@"Monitors system metrics and sends them to a statsd-compatible server.");
                hostConfigurator.SetServiceName(@"Spectator");
            });
        }