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 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 GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys, Origin); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", timerValueSource); payloadBuilder.PayloadFormatted(). Should(). Be( "env.staging.timer.test.test_timer.host.server1.Total 1 0\nenv.staging.timer.test.test_timer.host.server1.Rate-1-Min 0.00 0\nenv.staging.timer.test.test_timer.host.server1.Rate-5-Min 0.00 0\nenv.staging.timer.test.test_timer.host.server1.Rate-15-Min 0.00 0\nenv.staging.timer.test.test_timer.host.server1.Samples 1 0\nenv.staging.timer.test.test_timer.host.server1.Last 1000.00 0\nenv.staging.timer.test.test_timer.host.server1.Count 1 0\nenv.staging.timer.test.test_timer.host.server1.Sum 1000.00 0\nenv.staging.timer.test.test_timer.host.server1.Min 1000.00 0\nenv.staging.timer.test.test_timer.host.server1.Max 1000.00 0\nenv.staging.timer.test.test_timer.host.server1.Mean 1000.00 0\nenv.staging.timer.test.test_timer.host.server1.Median 1000.00 0\nenv.staging.timer.test.test_timer.host.server1.StdDev 0.00 0\nenv.staging.timer.test.test_timer.host.server1.Percentile-999 1000.00 0\nenv.staging.timer.test.test_timer.host.server1.Percentile-99 1000.00 0\nenv.staging.timer.test.test_timer.host.server1.Percentile-98 1000.00 0\nenv.staging.timer.test.test_timer.host.server1.Percentile-95 1000.00 0\nenv.staging.timer.test.test_timer.host.server1.Percentile-75 1000.00 0\nenv.staging.timer.test.test_timer.host.server1.User-Last client1 0\nenv.staging.timer.test.test_timer.host.server1.User-Min client1 0\nenv.staging.timer.test.test_timer.host.server1.User-Max client1 0\n"); }
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 GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", meterValueSource); payloadBuilder.Payload().Format(_settings.GraphiteSettings.MetricNameFormatter).Should().NotBeNullOrWhiteSpace(); payloadBuilder.Clear(); payloadBuilder.Payload().Should().BeNull(); }
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 GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys, Origin); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", counterValueSource); payloadBuilder.PayloadFormatted(). Should(). Be( "counter.test.test_counter-SetItem.item.item1_value1.Total 1 0\ncounter.test.test_counter-SetItem.item.item2_value2.Total 1 0\ncounter.test.test_counter.value 2 0\n"); }
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 GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys, Origin); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", counterValueSource); payloadBuilder.PayloadFormatted(). Should(). Be( "env.staging.counter.test.test_counter-SetItem.host.server1.key1.value1.key2.value2.item.item1_value1.Total 1 0\nenv.staging.counter.test.test_counter-SetItem.host.server1.key1.value1.key2.value2.item.item1_value1.Percent 50.00 0\nenv.staging.counter.test.test_counter-SetItem.host.server1.key1.value1.key2.value2.item.item2_value2.Total 1 0\nenv.staging.counter.test.test_counter-SetItem.host.server1.key1.value1.key2.value2.item.item2_value2.Percent 50.00 0\nenv.staging.counter.test.test_counter.host.server1.key1.value1.key2.value2.value 2 0\n"); }
public Task WriteAsync(HttpContext context, MetricsDataValueSource metricsData, CancellationToken token = default(CancellationToken)) { var payloadBuilder = new GraphitePayloadBuilder(); var formatter = new MetricDataValueSourceFormatter(); formatter.Build(metricsData, payloadBuilder); return(context.Response.WriteAsync(payloadBuilder.PayloadFormatted(), token)); }
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 GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys, Origin); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", apdexValueSource); payloadBuilder.PayloadFormatted().Should().Be("apdex.test.test_apdex.Samples 0 0\napdex.test.test_apdex.Score 0.00 0\napdex.test.test_apdex.Satisfied 0 0\napdex.test.test_apdex.Tolerating 0 0\napdex.test.test_apdex.Frustrating 0 0\n"); }
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 GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys, Origin); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", gaugeValueSource); payloadBuilder.PayloadFormatted().Should().Be("env.staging.gauge.test.gauge-group.host.server1.value 1.00 0\n"); }
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 GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys, Origin); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", gaugeValueSource); payloadBuilder.PayloadFormatted().Should().Be("gauge.test.test_gauge.value 1.00 0\n"); }
public IMetricReporter CreateMetricReporter(string name, ILoggerFactory loggerFactory) { var graphtieClient = new GraphiteClient( loggerFactory, _settings.GraphiteSettings, _settings.HttpPolicy); var payloadBuilder = new GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys); return(new ReportRunner <GraphitePayload>( async p => { var result = await graphtieClient.WriteAsync(p.Payload()); return result.Success; }, payloadBuilder, _settings.ReportInterval, name, loggerFactory)); }
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 GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys, Origin); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", counterValueSource); payloadBuilder.PayloadFormatted().Should().Be("env.staging.counter.test.test_counter.host.server1.value 1 0\n"); }
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 GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys, Origin); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", counterValueSource); payloadBuilder.PayloadFormatted().Should().Be("counter.test.test_counter.value 1 0\n"); }
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 GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys, Origin); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", apdexValueSource); payloadBuilder.PayloadFormatted(). Should(). Be("env.staging.apdex.test.test_apdex.host.server1.Samples 0 0\nenv.staging.apdex.test.test_apdex.host.server1.Score 0.00 0\nenv.staging.apdex.test.test_apdex.host.server1.Satisfied 0 0\nenv.staging.apdex.test.test_apdex.host.server1.Tolerating 0 0\nenv.staging.apdex.test.test_apdex.host.server1.Frustrating 0 0\n"); }
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_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 GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys, Origin); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", histogramValueSource); payloadBuilder.PayloadFormatted(). Should(). Be( "env.staging.histogram.test.test_histogram.host.server1.Samples 1 0\nenv.staging.histogram.test.test_histogram.host.server1.Last 1000.00 0\nenv.staging.histogram.test.test_histogram.host.server1.Count 1 0\nenv.staging.histogram.test.test_histogram.host.server1.Sum 1000.00 0\nenv.staging.histogram.test.test_histogram.host.server1.Min 1000.00 0\nenv.staging.histogram.test.test_histogram.host.server1.Max 1000.00 0\nenv.staging.histogram.test.test_histogram.host.server1.Mean 1000.00 0\nenv.staging.histogram.test.test_histogram.host.server1.Median 1000.00 0\nenv.staging.histogram.test.test_histogram.host.server1.StdDev 0.00 0\nenv.staging.histogram.test.test_histogram.host.server1.Percentile-999 1000.00 0\nenv.staging.histogram.test.test_histogram.host.server1.Percentile-99 1000.00 0\nenv.staging.histogram.test.test_histogram.host.server1.Percentile-98 1000.00 0\nenv.staging.histogram.test.test_histogram.host.server1.Percentile-95 1000.00 0\nenv.staging.histogram.test.test_histogram.host.server1.Percentile-75 1000.00 0\nenv.staging.histogram.test.test_histogram.host.server1.User-Last client1 0\nenv.staging.histogram.test.test_histogram.host.server1.User-Min client1 0\nenv.staging.histogram.test.test_histogram.host.server1.User-Max client1 0\n"); }