Exemplo n.º 1
0
        public void can_load_json_formatted_configuration()
        {
            var config = JsonSpectatorConfiguration.LoadConfigFromString(
                @"{
                      ""statsdHost"": ""localhost"",
                      ""statsdPort"": 8125,
                      ""metricPrefix"": ""net.verrus.{machine}"",
                      ""interval"":  ""00:00:05"",
                      ""metrics"": [
                        {
                          ""source"": ""performanceCounter"",
                          ""path"": ""\\Processor(_Total)\\Interrupts/sec"",
                          ""type"": ""gauge"",
                          ""template"": ""system.processor.interrupts_per_sec""
                        }
                      ]
                    }");

            Assert.That(config.StatsdHost, Is.EqualTo("localhost"));
            Assert.That(config.StatsdPort, Is.EqualTo(8125));
            Assert.That(config.MetricPrefix, Is.EqualTo("net.verrus.{machine}"));
            Assert.That(config.Interval, Is.EqualTo(TimeSpan.FromSeconds(5)));

            Assert.That(config.Metrics.Count, Is.EqualTo(1));
            Assert.That(config.Metrics[0].Source, Is.EqualTo(MetricSource.PerformanceCounter));
            Assert.That(config.Metrics[0].Path, Is.EqualTo("\\Processor(_Total)\\Interrupts/sec"));
            Assert.That(config.Metrics[0].Type, Is.EqualTo(MetricType.Gauge));
            Assert.That(config.Metrics[0].Template, Is.EqualTo("system.processor.interrupts_per_sec"));
        }
        public ConsulSpectatorOverrideConfiguration(string host, string key)
        {
            var client = string.IsNullOrEmpty(host) ? new Client() : new Client(new ConsulClientConfiguration {
                Address = host
            });

            var getPair = client.KV.Get(key);

            _configContents = Encoding.UTF8.GetString(getPair.Response.Value, 0, getPair.Response.Value.Length);

            Log.InfoFormat("Using configuration read from consul host '{0}', in key '{1}'", host, key);

            _innerConfiguration = JsonSpectatorConfiguration.LoadConfigFromString(_configContents);
        }
Exemplo n.º 3
0
        public void SetUp()
        {
            _baseConfig = JsonSpectatorConfiguration.LoadConfigFromString(@"{
                      ""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""
                        }
                      ]
                    }");

            _overrideConfig = JsonSpectatorConfiguration.LoadConfigFromString(@"{
                      ""statsdHost"": ""overridehost"",
                      ""statsdPort"": 8126,
                      ""metricPrefix"": ""override.prefix"",
                      ""interval"":  ""00:00:02"",
                      ""metrics"": [
                        {
                          ""source"": ""performanceCounter"",
                          ""path"": ""\\Processor(_Total)\\Interrupts/sec"",
                          ""type"": ""gauge"",
                          ""template"": ""override.performance.counter""
                        },
                        {
                          ""source"": ""performanceCounter"",
                          ""path"": ""\\Processor(_Total)\\% Processor Time"",
                          ""type"": ""gauge"",
                          ""template"": ""overriden.performance.counter""
                        }
                      ]
                    }");

            _combinedConfig = new CombinedSpectatorConfiguration(_baseConfig, _overrideConfig);
        }
Exemplo n.º 4
0
        public void when_given_two_configurations_with_differences_then_a_summary_is_created()
        {
            var first = JsonSpectatorConfiguration.LoadConfigFromString(@"{
                      ""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""
                        }
                      ]
                    }");

            var second = JsonSpectatorConfiguration.LoadConfigFromString(@"{
                      ""statsdHost"": ""overridehost"",
                      ""statsdPort"": 8126,
                      ""metricPrefix"": ""override.prefix"",
                      ""interval"":  ""00:00:02"",
                      ""metrics"": [
                        {
                          ""source"": ""performanceCounter"",
                          ""path"": ""\\Processor(_Total)\\% Processor Time"",
                          ""type"": ""gauge"",
                          ""template"": ""base.performance.counter""
                        },
                        {
                          ""source"": ""performanceCounter"",
                          ""path"": ""\\Processor(_Total)\\Some Other Thing"",
                          ""type"": ""gauge"",
                          ""template"": ""overridden.performance.counter""
                        }
                      ]
                    }");

            var summary = new ConfigurationDifferenceSummary(first, second);

            Assert.That(summary.ToString(), Is.EqualTo("StatsdHost: 'basehost' → 'overridehost'\r\nStatsdPort: '8125' → '8126'\r\nMetricPrefix: 'base.prefix' → 'override.prefix'\r\nInterval: '00:00:01' → '00:00:02'\r\nMetrics:\r\n    Replaced '\\Processor(_Total)\\Interrupts/sec' → 'base.performance.counter' with '\\Processor(_Total)\\% Processor Time' → 'base.performance.counter'\r\n    Added '\\Processor(_Total)\\Some Other Thing' → 'overridden.performance.counter'\r\n"));
        }