示例#1
0
        public void can_report_counter_with_items_and_custom_data_keys()
        {
            var metricsMock = new Mock <IMetrics>();
            var counter     = new DefaultCounterMetric();

            counter.Increment(new MetricSetItem("item1", "value1"), 1);
            counter.Increment(new MetricSetItem("item2", "value2"), 1);
            var counterValueSource = new CounterValueSource(
                "test counter",
                ConstantValue.Provider(counter.Value),
                Unit.None,
                new MetricTags(new[] { "key1", "key2" }, new[] { "value1", "value2" }));
            var payloadBuilder = new TestPayloadBuilder();
            var customDataKeys = new MetricValueDataKeys(
                counter: new Dictionary <CounterValueDataKeys, string>
            {
                { CounterValueDataKeys.SetItemPercent, "%" },
                { CounterValueDataKeys.Total, "count" }
            });
            var reporter = new TestReporter(payloadBuilder, customDataKeys);

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

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_counter__items key1=value1 key2=value2 item=item1:value1 mtype=counter count=1i %=50" +
                Environment.NewLine +
                "test__test_counter__items key1=value1 key2=value2 item=item2:value2 mtype=counter count=1i %=50" +
                Environment.NewLine +
                "test__test_counter key1=value1 key2=value2 mtype=counter value=2i" + Environment.NewLine);
        }
示例#2
0
        public async Task can_pack_metrics_with_custom_histogram_keys()
        {
            // Arrange
            var dataKeys = new MetricValueDataKeys(
                histogram: new Dictionary <HistogramValueDataKeys, string> {
                { HistogramValueDataKeys.P75, "75th_percentile" }
            });
            var token          = CancellationToken.None;
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(
                payloadBuilder,
                dataKeys);
            var filter = new DefaultMetricsFilter().WithEnvironmentInfo(false);

            // Act
            await _reportGenerator.GenerateAsync(reporter, _metrics, filter, token);

            var payload = payloadBuilder.PayloadFormatted();

            // Assert
            payload.Should().
            Be(
                "application__test_counter tag1=value mtype=counter value=1i" + Environment.NewLine +
                "application__test_gauge mtype=gauge value=8" + Environment.NewLine +
                "application__test_histogram mtype=histogram samples=1i last=5 count.hist=1i sum=5 min=5 max=5 mean=5 median=5 stddev=0 p999=5 p99=5 p98=5 p95=5 75th_percentile=5" +
                Environment.NewLine +
                "application__test_meter tag2=value mtype=meter count.meter=1i rate1m=0 rate5m=0 rate15m=0 rate.mean=6000" +
                Environment.NewLine +
                "application__test_timer mtype=timer count.meter=1i rate1m=0 rate5m=0 rate15m=0 rate.mean=6000 samples=1i last=10 count.hist=1i sum=10 min=10 max=10 mean=10 median=10 stddev=0 p999=10 p99=10 p98=10 p95=10 75th_percentile=10" +
                Environment.NewLine);
        }
示例#3
0
        public void can_report_counter_with_items_with_option_not_to_report_percentage()
        {
            var metricsMock = new Mock <IMetrics>();
            var counter     = new DefaultCounterMetric();

            counter.Increment(new MetricSetItem("item1", "value1"), 1);
            counter.Increment(new MetricSetItem("item2", "value2"), 1);
            var counterValueSource = new CounterValueSource(
                "test counter",
                ConstantValue.Provider(counter.Value),
                Unit.None,
                MetricTags.Empty,
                reportItemPercentages: false);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

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

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_counter__items item=item1:value1 mtype=counter total=1i" + Environment.NewLine +
                "test__test_counter__items item=item2:value2 mtype=counter total=1i" + Environment.NewLine +
                "test__test_counter mtype=counter value=2i" + Environment.NewLine);
        }
示例#4
0
        public void can_report_counter_with_items_using_custom_key()
        {
            var dataKeys = new MetricValueDataKeys(
                counter: new Dictionary <CounterValueDataKeys, string> {
                { CounterValueDataKeys.MetricSetItemSuffix, " setitem" }
            });
            var metricsMock = new Mock <IMetrics>();
            var counter     = new DefaultCounterMetric();

            counter.Increment(new MetricSetItem("item1", "value1"), 1);
            counter.Increment(new MetricSetItem("item2", "value2"), 1);
            var counterValueSource = new CounterValueSource(
                "test counter",
                ConstantValue.Provider(counter.Value),
                Unit.None,
                MetricTags.Empty);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder, dataKeys);

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

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_counter_setitem item=item1:value1 mtype=counter total=1i percent=50" + Environment.NewLine +
                "test__test_counter_setitem item=item2:value2 mtype=counter total=1i percent=50" + Environment.NewLine +
                "test__test_counter mtype=counter value=2i" + Environment.NewLine);
        }
示例#5
0
        public void can_report_counter_with_items_tags_when_multidimensional()
        {
            var counterTags = new MetricTags(new[] { "key1", "key2" }, new[] { "value1", "value2" });
            var metricsMock = new Mock <IMetrics>();
            var counter     = new DefaultCounterMetric();

            counter.Increment(new MetricSetItem("item1", "value1"), 1);
            counter.Increment(new MetricSetItem("item2", "value2"), 1);
            var counterValueSource = new CounterValueSource(
                "test counter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(counter.Value),
                Unit.None,
                MetricTags.Concat(_tags, counterTags));
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

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

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_counter__items host=server1 env=staging key1=value1 key2=value2 item=item1:value1 mtype=counter total=1i percent=50" +
                Environment.NewLine +
                "test__test_counter__items host=server1 env=staging key1=value1 key2=value2 item=item2:value2 mtype=counter total=1i percent=50" +
                Environment.NewLine +
                "test__test_counter host=server1 env=staging key1=value1 key2=value2 mtype=counter value=2i" + Environment.NewLine);
        }
示例#6
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();
        }
示例#7
0
        public void can_report_timers()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var timer       = new DefaultTimerMetric(_defaultReservoir, clock);

            timer.Record(1000, TimeUnit.Milliseconds, "client1");
            var timerValueSource = new TimerValueSource(
                "test timer",
                ConstantValue.Provider(timer.Value),
                Unit.None,
                TimeUnit.Minutes,
                TimeUnit.Milliseconds,
                MetricTags.Empty);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

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

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_timer mtype=timer unit=none unit_dur=ms unit_rate=min count.meter=1i rate1m=0 rate5m=0 rate15m=0 samples=1i last=1000 count.hist=1i sum=1000 min=1000 max=1000 mean=1000 median=1000 stddev=0 p999=1000 p99=1000 p98=1000 p95=1000 p75=1000 user.last=\"client1\" user.min=\"client1\" user.max=\"client1\"" +
                Environment.NewLine);
        }
示例#8
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);
        }
示例#9
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);
        }
示例#10
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);
        }
示例#11
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);
        }
示例#12
0
        public async Task can_pack_metrics()
        {
            // Arrange
            var token          = CancellationToken.None;
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);
            var filter         = new DefaultMetricsFilter().WithEnvironmentInfo(false);

            // Act
            await _fixture.ReportGenerator.GenerateAsync(reporter, _fixture.Metrics(), filter, token);

            var payload = payloadBuilder.PayloadFormatted();

            // Assert
            payload.Should().
            Be(
                "application__test_counter tag1=value mtype=counter unit=req value=1i" + Environment.NewLine +
                "application__test_gauge mtype=gauge unit=none value=8" + Environment.NewLine +
                "application__test_histogram mtype=histogram unit=req samples=1i last=5 count.hist=1i sum=5 min=5 max=5 mean=5 median=5 stddev=0 p999=5 p99=5 p98=5 p95=5 p75=5" +
                Environment.NewLine +
                "application__test_meter tag2=value mtype=meter unit=none unit_rate=min count.meter=1i rate1m=0 rate5m=0 rate15m=0 rate.mean=3000" +
                Environment.NewLine +
                "application__test_timer mtype=timer unit=req unit_dur=ms unit_rate=min count.meter=1i rate1m=0 rate5m=0 rate15m=0 rate.mean=3000 samples=1i last=10 count.hist=1i sum=10 min=10 max=10 mean=10 median=10 stddev=0 p999=10 p99=10 p98=10 p95=10 p75=10" +
                Environment.NewLine);
        }
示例#13
0
        public void can_report_timers__when_multidimensional()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var timer       = new DefaultTimerMetric(_defaultReservoir, clock);

            timer.Record(1000, TimeUnit.Milliseconds, "client1");
            var timerValueSource = new TimerValueSource(
                "test timer" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(timer.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                TimeUnit.Milliseconds,
                _tags);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

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

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_timer host=server1 env=staging mtype=timer count.meter=1i rate1m=0 rate5m=0 rate15m=0 samples=1i last=1000 count.hist=1i sum=1000 min=1000 max=1000 mean=1000 median=1000 stddev=0 p999=1000 p99=1000 p98=1000 p95=1000 p75=1000 user.last=\"client1\" user.min=\"client1\" user.max=\"client1\"" +
                Environment.NewLine);
        }
示例#14
0
        public void can_report_counter_with_items_and_tags()
        {
            var metricsMock = new Mock <IMetrics>();
            var counter     = new DefaultCounterMetric();

            counter.Increment(new MetricSetItem("item1", "value1"), 1);
            counter.Increment(new MetricSetItem("item2", "value2"), 1);
            var counterValueSource = new CounterValueSource(
                "test counter",
                ConstantValue.Provider(counter.Value),
                Unit.None,
                new MetricTags(new[] { "key1", "key2" }, new[] { "value1", "value2" }));
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

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

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_counter__items key1=value1 key2=value2 item=item1:value1 mtype=counter total=1i percent=50" +
                Environment.NewLine +
                "test__test_counter__items key1=value1 key2=value2 item=item2:value2 mtype=counter total=1i percent=50" +
                Environment.NewLine +
                "test__test_counter key1=value1 key2=value2 mtype=counter value=2i" + Environment.NewLine);
        }
示例#15
0
        public void can_report_gauges__when_multidimensional()
        {
            var metricsMock      = new Mock <IMetrics>();
            var gauge            = new FunctionGauge(() => 1);
            var gaugeValueSource = new GaugeValueSource(
                "gauge-group" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(gauge.Value),
                Unit.None,
                _tags);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

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

            payloadBuilder.PayloadFormatted().Should().Be("test__gauge-group host=server1 env=staging mtype=gauge value=1" + Environment.NewLine);
        }
示例#16
0
        public void can_report_gauges()
        {
            var metricsMock      = new Mock <IMetrics>();
            var gauge            = new FunctionGauge(() => 1);
            var gaugeValueSource = new GaugeValueSource(
                "test gauge",
                ConstantValue.Provider(gauge.Value),
                Unit.None,
                MetricTags.Empty);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

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

            payloadBuilder.PayloadFormatted().Should().Be("test__test_gauge mtype=gauge value=1" + Environment.NewLine);
        }
示例#17
0
        public void can_report_counters__when_multidimensional()
        {
            var metricsMock = new Mock <IMetrics>();
            var counter     = new DefaultCounterMetric();

            counter.Increment(1);
            var counterValueSource = new CounterValueSource(
                "test counter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(counter.Value),
                Unit.None,
                _tags);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

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

            payloadBuilder.PayloadFormatted().Should().Be("test__test_counter host=server1 env=staging mtype=counter value=1i" + Environment.NewLine);
        }
示例#18
0
        public void can_report_counters()
        {
            var metricsMock = new Mock <IMetrics>();
            var counter     = new DefaultCounterMetric();

            counter.Increment(1);
            var counterValueSource = new CounterValueSource(
                "test counter",
                ConstantValue.Provider(counter.Value),
                Unit.None,
                MetricTags.Empty);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

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

            payloadBuilder.PayloadFormatted().Should().Be("test__test_counter mtype=counter value=1i" + Environment.NewLine);
        }
示例#19
0
        // [Fact]
        // public async Task on_end_report_clears_playload()
        // {
        //     var metricsMock = new Mock<IMetrics>();
        //     var payloadBuilderMock = new Mock<IMetricPayloadBuilder<TestMetricPayload>>();
        //     payloadBuilderMock.Setup(p => p.Clear());
        //     var items = CreateReporterAndPayloadBuilder(payloadBuilderMock.Object);

        //     await items.Item1.EndAndFlushReportRunAsync(metricsMock.Object).ConfigureAwait(false);

        //    payloadBuilderMock.Verify(p => p.Clear(), Times.Once);
        // }

        // [Fact]
        // public void when_disposed_clears_playload()
        // {
        //     var payloadBuilderMock = new Mock<IMetricPayloadBuilder<TestMetricPayload>>();
        //     payloadBuilderMock.Setup(p => p.Clear());
        //     var items = CreateReporterAndPayloadBuilder();

        //     items.Item1.Dispose();

        //     payloadBuilderMock.Verify(p => p.Clear(), Times.Once);
        // }

        private static (IMetricReporter, IMetricPayloadBuilder <TestMetricPayload>) CreateReporterAndPayloadBuilder()
        {
            var loggerFactory  = new LoggerFactory();
            var settings       = new TestReporterSettings();
            var payloadBuilder = new TestPayloadBuilder(settings.MetricNameFormatter, settings.DataKeys);

            var reporter = new ReportRunner <TestMetricPayload>(
                p =>
            {
                var payload = p.Payload();
                return(AppMetricsTaskCache.SuccessTask);
            },
                payloadBuilder,
                settings.ReportInterval,
                "Test Reporter",
                loggerFactory);

            return(reporter, payloadBuilder);
        }
示例#20
0
        public void can_report_apdex__when_multidimensional()
        {
            var metricsMock      = new Mock <IMetrics>();
            var clock            = new TestClock();
            var gauge            = new DefaultApdexMetric(_defaultReservoir, clock, false);
            var apdexValueSource = new ApdexValueSource(
                "test apdex" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(gauge.Value),
                _tags,
                resetOnReporting: false);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = CreateReporter(payloadBuilder);

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

            payloadBuilder.PayloadFormatted().
            Should().
            Be("test__test_apdex host=server1 env=staging mtype=apdex samples=0i score=0 satisfied=0i tolerating=0i frustrating=0i" + Environment.NewLine);
        }
示例#21
0
        public void can_report_apdex()
        {
            var metricsMock      = new Mock <IMetrics>();
            var clock            = new TestClock();
            var gauge            = new DefaultApdexMetric(_defaultReservoir, clock, false);
            var apdexValueSource = new ApdexValueSource(
                "test apdex",
                ConstantValue.Provider(gauge.Value),
                MetricTags.Empty,
                false);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

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

            payloadBuilder.PayloadFormatted().
            Should().
            Be("test__test_apdex mtype=apdex samples=0i score=0 satisfied=0i tolerating=0i frustrating=0i" + Environment.NewLine);
        }
示例#22
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 TestPayloadBuilder();
            var reporter       = CreateReporter(payloadBuilder);

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

            payloadBuilder.PayloadFormatted().Should().Be("test__test_meter mtype=meter count.meter=1i rate1m=0 rate5m=0 rate15m=0" + Environment.NewLine);
        }
示例#23
0
        public void can_report_histograms_when_multidimensional()
        {
            var metricsMock = new Mock <IMetrics>();
            var histogram   = new DefaultHistogramMetric(_defaultReservoir);

            histogram.Update(1000, "client1");
            var histogramValueSource = new HistogramValueSource(
                "test histogram" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(histogram.Value),
                Unit.None,
                _tags);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = CreateReporter(payloadBuilder);

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

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_histogram host=server1 env=staging mtype=histogram samples=1i last=1000 count.hist=1i sum=1000 min=1000 max=1000 mean=1000 median=1000 stddev=0 p999=1000 p99=1000 p98=1000 p95=1000 p75=1000 user.last=\"client1\" user.min=\"client1\" user.max=\"client1\"" + Environment.NewLine);
        }
示例#24
0
        public void can_report_histograms()
        {
            var metricsMock = new Mock <IMetrics>();
            var histogram   = new DefaultHistogramMetric(_defaultReservoir);

            histogram.Update(1000, "client1");
            var histogramValueSource = new HistogramValueSource(
                "test histogram",
                ConstantValue.Provider(histogram.Value),
                Unit.None,
                MetricTags.Empty);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

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

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_histogram mtype=histogram unit=none samples=1i last=1000 count.hist=1i sum=1000 min=1000 max=1000 mean=1000 median=1000 stddev=0 p999=1000 p99=1000 p98=1000 p95=1000 p75=1000 user.last=\"client1\" user.min=\"client1\" user.max=\"client1\"" +
                Environment.NewLine);
        }