Exemple #1
0
        public void can_report_meters_with_items_tags_when_multidimensional()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                _tags);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_meter__items host=server1 env=staging item=item1:value1 mtype=meter count.meter=1i rate1m=0 rate5m=0 rate15m=0 percent=50" +
                Environment.NewLine +
                "test__test_meter__items host=server1 env=staging item=item2:value2 mtype=meter count.meter=1i rate1m=0 rate5m=0 rate15m=0 percent=50" +
                Environment.NewLine +
                "test__test_meter host=server1 env=staging mtype=meter count.meter=2i rate1m=0 rate5m=0 rate15m=0" +
                Environment.NewLine);
        }
Exemple #2
0
        public void can_report_meters_with_items_tags_when_multidimensional()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                _tags);
            var payloadBuilder = new LineProtocolPayloadBuilder(_settings.DataKeys, _settings.MetricNameFormatter);
            var reporter       = CreateReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            payloadBuilder.PayloadFormatted(false).
            Should().
            Be(
                "test__test_meter__items,host=server1,env=staging,item=item1:value1,mtype=meter,unit=none,unit_rate=ms count.meter=1i,rate1m=0,rate5m=0,rate15m=0,percent=50\ntest__test_meter__items,host=server1,env=staging,item=item2:value2,mtype=meter,unit=none,unit_rate=ms count.meter=1i,rate1m=0,rate5m=0,rate15m=0,percent=50\ntest__test_meter,host=server1,env=staging,mtype=meter,unit=none,unit_rate=ms count.meter=2i,rate1m=0,rate5m=0,rate15m=0\n");
        }
        public void can_report_meters_with_items()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                MetricTags.Empty);
            var payloadBuilder = new LineProtocolPayloadBuilder();
            var reporter       = CreateReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_meter__items,item=item1:value1 count.meter=1i,rate1m=0,rate5m=0,rate15m=0,percent=50\ntest__test_meter__items,item=item2:value2 count.meter=1i,rate1m=0,rate5m=0,rate15m=0,percent=50\ntest__test_meter count.meter=2i,rate1m=0,rate5m=0,rate15m=0\n");
        }
Exemple #4
0
        public void can_calculate_the_hit_ratio_as_a_guage_with_one_min_rate_as_default()
        {
            var clock     = new TestClock();
            var scheduler = new TestTaskScheduler(clock);

            var cacheHitMeter = new DefaultMeterMetric(clock, scheduler);
            var dbQueryTimer  = new DefaultTimerMetric(new DefaultAlgorithmRReservoir(1028), clock);

            foreach (var index in Enumerable.Range(0, 1000))
            {
                using (dbQueryTimer.NewContext())
                {
                    clock.Advance(TimeUnit.Milliseconds, 100);
                }

                if (index % 2 == 0)
                {
                    cacheHitMeter.Mark();
                }
            }

            var cacheHitRatioGauge = new HitRatioGauge(cacheHitMeter, dbQueryTimer);

            cacheHitRatioGauge.Value.Should().BeGreaterThan(0.0);
        }
Exemple #5
0
        public void can_clear_payload()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                MetricTags.Empty);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = CreateReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            var sb = new StringBuilder();

            payloadBuilder.Payload().Format(sb);
            sb.ToString().Should().NotBeNullOrWhiteSpace();

            payloadBuilder.Clear();

            payloadBuilder.Payload().Should().BeNull();
        }
Exemple #6
0
        public void can_report_meters_with_items()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                MetricTags.Empty);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_meter__items item=item1:value1 mtype=meter unit=none unit_rate=ms count.meter=1i rate1m=0 rate5m=0 rate15m=0 percent=50" +
                Environment.NewLine +
                "test__test_meter__items item=item2:value2 mtype=meter unit=none unit_rate=ms count.meter=1i rate1m=0 rate5m=0 rate15m=0 percent=50" +
                Environment.NewLine +
                "test__test_meter mtype=meter unit=none unit_rate=ms count.meter=2i rate1m=0 rate5m=0 rate15m=0" + Environment.NewLine);
        }
        public void can_report_meters_with_items_tags_when_multidimensional()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                _tags);
            var payloadBuilder = new GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys, Origin);

            var reporter = CreateReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "env.staging.meter.test.test_meter-SetItem.host.server1.item.item1_value1.Total 1 0\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item1_value1.Rate-1-Min 0.00 0\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item1_value1.Rate-5-Min 0.00 0\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item1_value1.Rate-15-Min 0.00 0\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item1_value1.Percent 50.00 0\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item2_value2.Total 1 0\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item2_value2.Rate-1-Min 0.00 0\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item2_value2.Rate-5-Min 0.00 0\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item2_value2.Rate-15-Min 0.00 0\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item2_value2.Percent 50.00 0\nenv.staging.meter.test.test_meter.host.server1.Total 2 0\nenv.staging.meter.test.test_meter.host.server1.Rate-1-Min 0.00 0\nenv.staging.meter.test.test_meter.host.server1.Rate-5-Min 0.00 0\nenv.staging.meter.test.test_meter.host.server1.Rate-15-Min 0.00 0\n");
        }
        public MeterMetricTests()
        {
            _clock = new TestClock();
            var schedular = new TestMeterTickerScheduler(_clock);

            _meter = new DefaultMeterMetric(_clock, schedular);
        }
Exemple #9
0
        public void can_report_meters_with_items_tags_and_group()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                "requests",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                new MetricTags(new[] { "key1", "key2" }, new[] { "value1", "value2" }));
            var payloadBuilder = new LineProtocolPayloadBuilder();
            var reporter       = CreateReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__requests__items,group_item=test_meter,key1=value1,key2=value2,item=item1:value1 count.meter=1i,rate1m=0,rate5m=0,rate15m=0,rate.mean=Infinity,percent=50\ntest__requests__items,group_item=test_meter,key1=value1,key2=value2,item=item2:value2 count.meter=1i,rate1m=0,rate5m=0,rate15m=0,rate.mean=Infinity,percent=50\ntest__requests,group_item=test_meter,key1=value1,key2=value2 count.meter=2i,rate1m=0,rate5m=0,rate15m=0,rate.mean=Infinity\n");
        }
Exemple #10
0
        public void can_report_meters_with_items_using_custom_item_key()
        {
            var dataKeys = new MetricValueDataKeys(
                meter: new Dictionary <MeterValueDataKeys, string> {
                { MeterValueDataKeys.MetricSetItemSuffix, " setitem" }
            });
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                MetricTags.Empty);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder, dataKeys);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_meter_setitem item=item1:value1 mtype=meter count.meter=1i rate1m=0 rate5m=0 rate15m=0 percent=50" +
                Environment.NewLine +
                "test__test_meter_setitem item=item2:value2 mtype=meter count.meter=1i rate1m=0 rate5m=0 rate15m=0 percent=50" +
                Environment.NewLine +
                "test__test_meter mtype=meter count.meter=2i rate1m=0 rate5m=0 rate15m=0" + Environment.NewLine);
        }
Exemple #11
0
        public async Task Can_report_meters_with_items()
        {
            // Arrange
            var expected =
                "test.test_meter__items.meter.item1:value1.value:1|c\n" +
                "test.test_meter__items.meter.item2:value2.value:1|c\n" +
                "test.test_meter.meter.value:2|c";
            var clock = new TestClock();
            var meter = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                MetricTags.Empty);

            // Act
            var valueSource = CreateValueSource("test", meters: meterValueSource);

            // Assert
            await AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), expected);
        }
Exemple #12
0
        public void can_report_meters_when_multidimensional()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(1);
            var meterValueSource = new MeterValueSource(
                "test meter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                _tags);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_meter host=server1 env=staging mtype=meter unit=none unit_rate=ms count.meter=1i rate1m=0 rate5m=0 rate15m=0" +
                Environment.NewLine);
        }
Exemple #13
0
        public async Task Can_report_meters_with_items_tags_when_multidimensional()
        {
            // Arrange
            var expected =
                "test.test_meter__items.meter.item1:value1.value:1|m|#host:server1,env:staging,unit:none,unit_rate:ms,timestamp:1483232461\n" +
                "test.test_meter__items.meter.item2:value2.value:1|m|#host:server1,env:staging,unit:none,unit_rate:ms,timestamp:1483232461\n" +
                "test.test_meter.meter.value:2|m|#host:server1,env:staging,unit:none,unit_rate:ms,timestamp:1483232461";
            var clock = new TestClock();
            var meter = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                _tags);

            // Act
            var valueSource = CreateValueSource("test", meters: meterValueSource);

            // Assert
            await AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), expected);
        }
Exemple #14
0
        public void can_report_meters()
        {
            var expected = StringReporterSamples.Meters.ExtractStringReporterSampleFromResourceFile();
            var clock    = new TestClock();
            var sr       = new StringReporter();
            var metric   = new DefaultMeterMetric(clock, new TestTaskScheduler(clock));

            metric.Mark(1);

            sr.ReportMetric("test", new MeterValueSource("meter_name", metric, Unit.None, TimeUnit.Milliseconds, MetricTags.None));

            AssertReportResult(sr.Result, expected);
        }
Exemple #15
0
        public async Task Meters_should_not_be_sampled()
        {
            // Arrange
            var sources   = new List <MetricsDataValueSource>();
            var timeStamp = _timestamp;

            var expected =
                "test.test_meter.meter.value:4|c";

            // Act
            for (var i = 0; i < 100; ++i)
            {
                sources.Add(CreateMetricsDataValueSource(ref timeStamp));
            }
            var emittedData = (await Serialize(sources, 0.5)).Split('\n');

            // Assert
            emittedData.Length.Should().Be(100);
            emittedData[0].Should().Be(expected);

            MetricsDataValueSource CreateMetricsDataValueSource(ref DateTime timestamp)
            {
                var clock = new TestClock();
                var meter = new DefaultMeterMetric(clock);

                meter.Mark(1);
                meter.Mark(1);
                meter.Mark(1);
                meter.Mark(1);
                var meterValueSource = new MeterValueSource(
                    "test meter",
                    ConstantValue.Provider(meter.Value),
                    Unit.None,
                    TimeUnit.Milliseconds,
                    MetricTags.Empty);
                var valueSource = CreateValueSource("test", meters: meterValueSource);
                var result      = new MetricsDataValueSource(timestamp, new[] { valueSource });

                timestamp += TimeSpan.FromSeconds(1);
                return(result);
            }
        }
        public void can_report_meters()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                MetricTags.Empty);
            var items = CreateReporterAndPayloadBuilder();

            items.Item1.StartReportRun(metricsMock.Object);
            items.Item1.ReportMetric("test", meterValueSource);

            items.Item2.PayloadFormatted().Should().Be("test__test_meter mtype=meter unit=none unit_rate=ms count.meter=1i rate1m=0 rate5m=0 rate15m=0" + Environment.NewLine);
        }
        public void Can_report_meters()
        {
            // Arrange
            var expected = "test__test_meter,mtype=meter,unit=none,unit_rate=ms count.meter=1i,rate1m=0,rate5m=0,rate15m=0 1483232461000000000\n";
            var clock    = new TestClock();
            var meter    = new DefaultMeterMetric(clock);

            meter.Mark(1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                MetricTags.Empty);

            // Act
            var valueSource = CreateValueSource("test", meters: meterValueSource);

            // Assert
            AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), expected);
        }
Exemple #18
0
        public void can_report_meters()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                MetricTags.Empty);
            var payloadBuilder = new LineProtocolPayloadBuilder(_settings.DataKeys, _settings.MetricNameFormatter);
            var reporter       = CreateReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            payloadBuilder.PayloadFormatted(false).Should().Be("test__test_meter,mtype=meter,unit=none,unit_rate=ms count.meter=1i,rate1m=0,rate5m=0,rate15m=0\n");
        }
        public async Task Can_report_meters()
        {
            // Arrange
            var expected = "{\"series\":[{\"metric\":\"test.test_meter.meter.count.meter\",\"points\":[[1483232461,1]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter.meter.rate1m\",\"points\":[[1483232461,0]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter.meter.rate5m\",\"points\":[[1483232461,0]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter.meter.rate15m\",\"points\":[[1483232461,0]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"unit:none\",\"unit_rate:ms\"]}]}";
            var clock    = new TestClock();
            var meter    = new DefaultMeterMetric(clock);

            meter.Mark(1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                MetricTags.Empty);

            // Act
            var valueSource = CreateValueSource("test", meters: meterValueSource);

            // Assert
            await AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), FlushInterval, expected);
        }
        public async Task Can_report_meters_when_multidimensional()
        {
            // Arrange
            var expected = "test.test_meter.meter.value:1|c";
            var clock    = new TestClock();
            var meter    = new DefaultMeterMetric(clock);

            meter.Mark(1);
            var meterValueSource = new MeterValueSource(
                "test meter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                _tags);

            // Act
            var valueSource = CreateValueSource("test", meters: meterValueSource);

            // Assert
            await AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), expected);
        }
        public void Can_report_meters()
        {
            // Arrange
            var expected = "meter.test.test_meter.Total 1 1483232461\nmeter.test.test_meter.Rate-1-Min 0.00 1483232461\nmeter.test.test_meter.Rate-5-Min 0.00 1483232461\nmeter.test.test_meter.Rate-15-Min 0.00 1483232461\n";
            var clock    = new TestClock();
            var meter    = new DefaultMeterMetric(clock);

            meter.Mark(1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                MetricTags.Empty);

            // Act
            var valueSource = CreateValueSource("test", meters: meterValueSource);

            // Assert
            AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), expected);
        }
        public void Can_report_meters_when_multidimensional()
        {
            // Arrange
            var expected =
                "env.staging.meter.test.test_meter.host.server1.Total 1 1483232461\nenv.staging.meter.test.test_meter.host.server1.Rate-1-Min 0.00 1483232461\nenv.staging.meter.test.test_meter.host.server1.Rate-5-Min 0.00 1483232461\nenv.staging.meter.test.test_meter.host.server1.Rate-15-Min 0.00 1483232461\n";
            var clock = new TestClock();
            var meter = new DefaultMeterMetric(clock);

            meter.Mark(1);
            var meterValueSource = new MeterValueSource(
                "test meter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                _tags);

            // Act
            var valueSource = CreateValueSource("test", meters: meterValueSource);

            // Assert
            AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), expected);
        }
Exemple #23
0
        public async Task Can_report_meters()
        {
            // Arrange
            var expected =
                "test.test_meter.meter.value:1|m|#unit:none,unit_rate:ms,timestamp:1483232461";
            var clock = new TestClock();
            var meter = new DefaultMeterMetric(clock);

            meter.Mark(1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                MetricTags.Empty);

            // Act
            var valueSource = CreateValueSource("test", meters: meterValueSource);

            // Assert
            await AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), expected);
        }
Exemple #24
0
        public void Can_calculate_the_hit_ratio_as_a_guage()
        {
            var cacheHitMeter = new DefaultMeterMetric(_clock, _schedular);
            var queryTimer    = new DefaultTimerMetric(new DefaultAlgorithmRReservoir(1028), _clock);

            foreach (var index in Enumerable.Range(0, 1000))
            {
                using (queryTimer.NewContext())
                {
                    _clock.Advance(TimeUnit.Milliseconds, 100);
                }

                if (index % 2 == 0)
                {
                    cacheHitMeter.Mark();
                }
            }

            var cacheHitRatioGauge = new HitRatioGauge(cacheHitMeter, queryTimer, value => value.OneMinuteRate);

            cacheHitRatioGauge.Value.Should().BeGreaterThan(0.0);
        }
        public void can_report_meters()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                MetricTags.Empty);
            var payloadBuilder = new GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys, Origin);

            var reporter = CreateReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            payloadBuilder.PayloadFormatted().Should().Be("meter.test.test_meter.Total 1 0\nmeter.test.test_meter.Rate-1-Min 0.00 0\nmeter.test.test_meter.Rate-5-Min 0.00 0\nmeter.test.test_meter.Rate-15-Min 0.00 0\n");
        }
        public void Can_report_meters_when_multidimensional()
        {
            // Arrange
            var expected =
                "test__test_meter,host=server1,env=staging,mtype=meter,unit=none,unit_rate=ms count.meter=1i,rate1m=0,rate5m=0,rate15m=0 1483232461000000000\n";
            var clock = new TestClock();
            var meter = new DefaultMeterMetric(clock);

            meter.Mark(1);
            var meterValueSource = new MeterValueSource(
                "test meter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                _tags);

            // Act
            var valueSource = CreateValueSource("test", meters: meterValueSource);

            // Assert
            AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), expected);
        }
Exemple #27
0
        public async Task Can_report_meters_with_items_tags_when_multidimensional()
        {
            // Arrange
            var expected =
                "test__test_meter__items,host=server1,env=staging,item=item1:value1,mtype=meter,unit=none,unit_rate=ms count.meter=1i,rate1m=0,rate5m=0,rate15m=0,percent=50 1483232461000000000\ntest__test_meter__items,host=server1,env=staging,item=item2:value2,mtype=meter,unit=none,unit_rate=ms count.meter=1i,rate1m=0,rate5m=0,rate15m=0,percent=50 1483232461000000000\ntest__test_meter,host=server1,env=staging,mtype=meter,unit=none,unit_rate=ms count.meter=2i,rate1m=0,rate5m=0,rate15m=0 1483232461000000000\n";
            var clock = new TestClock();
            var meter = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                _tags);

            // Act
            var valueSource = CreateValueSource("test", meters: meterValueSource);

            // Assert
            await AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), expected);
        }
Exemple #28
0
        public async Task Can_report_meters_with_items_tags_when_multidimensional()
        {
            // Arrange
            var expected =
                "env.staging.meter.test.test_meter-SetItem.host.server1.item.item1_value1.Total 1 1483232461\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item1_value1.Rate-1-Min 0.00 1483232461\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item1_value1.Rate-5-Min 0.00 1483232461\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item1_value1.Rate-15-Min 0.00 1483232461\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item1_value1.Percent 50.00 1483232461\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item2_value2.Total 1 1483232461\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item2_value2.Rate-1-Min 0.00 1483232461\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item2_value2.Rate-5-Min 0.00 1483232461\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item2_value2.Rate-15-Min 0.00 1483232461\nenv.staging.meter.test.test_meter-SetItem.host.server1.item.item2_value2.Percent 50.00 1483232461\nenv.staging.meter.test.test_meter.host.server1.Total 2 1483232461\nenv.staging.meter.test.test_meter.host.server1.Rate-1-Min 0.00 1483232461\nenv.staging.meter.test.test_meter.host.server1.Rate-5-Min 0.00 1483232461\nenv.staging.meter.test.test_meter.host.server1.Rate-15-Min 0.00 1483232461\n";
            var clock = new TestClock();
            var meter = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                _tags);

            // Act
            var valueSource = CreateValueSource("test", meters: meterValueSource);

            // Assert
            await AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), expected);
        }
        public async Task Can_report_meters_with_items_tags_when_multidimensional()
        {
            // Arrange
            var expected =
                "{\"series\":[{\"metric\":\"test.test_meter__items.meter.count.meter\",\"points\":[[1483232461,1]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"host:server1\",\"env:staging\",\"item:item1:value1\",\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter__items.meter.rate1m\",\"points\":[[1483232461,0]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"host:server1\",\"env:staging\",\"item:item1:value1\",\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter__items.meter.rate5m\",\"points\":[[1483232461,0]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"host:server1\",\"env:staging\",\"item:item1:value1\",\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter__items.meter.rate15m\",\"points\":[[1483232461,0]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"host:server1\",\"env:staging\",\"item:item1:value1\",\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter__items.meter.percent\",\"points\":[[1483232461,50]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"host:server1\",\"env:staging\",\"item:item1:value1\",\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter__items.meter.count.meter\",\"points\":[[1483232461,1]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"host:server1\",\"env:staging\",\"item:item2:value2\",\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter__items.meter.rate1m\",\"points\":[[1483232461,0]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"host:server1\",\"env:staging\",\"item:item2:value2\",\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter__items.meter.rate5m\",\"points\":[[1483232461,0]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"host:server1\",\"env:staging\",\"item:item2:value2\",\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter__items.meter.rate15m\",\"points\":[[1483232461,0]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"host:server1\",\"env:staging\",\"item:item2:value2\",\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter__items.meter.percent\",\"points\":[[1483232461,50]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"host:server1\",\"env:staging\",\"item:item2:value2\",\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter.meter.count.meter\",\"points\":[[1483232461,2]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"host:server1\",\"env:staging\",\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter.meter.rate1m\",\"points\":[[1483232461,0]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"host:server1\",\"env:staging\",\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter.meter.rate5m\",\"points\":[[1483232461,0]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"host:server1\",\"env:staging\",\"unit:none\",\"unit_rate:ms\"]},{\"metric\":\"test.test_meter.meter.rate15m\",\"points\":[[1483232461,0]],\"type\":\"rate\",\"interval\":10,\"tags\":[\"host:server1\",\"env:staging\",\"unit:none\",\"unit_rate:ms\"]}]}";
            var clock = new TestClock();
            var meter = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                _tags);

            // Act
            var valueSource = CreateValueSource("test", meters: meterValueSource);

            // Assert
            await AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), FlushInterval, expected);
        }
Exemple #30
0
        public void can_report_meters_with_group()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                "http_transactions",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                MetricTags.Empty);
            var payloadBuilder = new LineProtocolPayloadBuilder();
            var reporter       = CreateReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be("test__http_transactions,group_item=test_meter count.meter=1i,rate1m=0,rate5m=0,rate15m=0,rate.mean=Infinity\n");
        }