示例#1
0
 public static JsonMeter FromMeter(MeterValueSource meter)
 {
     return new JsonMeter
     {
         Name = meter.Name,
         Count = meter.Value.Count,
         MeanRate = meter.Value.MeanRate,
         OneMinuteRate = meter.Value.OneMinuteRate,
         FiveMinuteRate = meter.Value.FiveMinuteRate,
         FifteenMinuteRate = meter.Value.FifteenMinuteRate,
         Unit = meter.Unit.Name,
         RateUnit = meter.RateUnit.Unit(),
         Items = meter.Value.Items.Select(i => new SetItem
         {
             Item = i.Item,
             Count = i.Value.Count,
             MeanRate = i.Value.MeanRate,
             OneMinuteRate = i.Value.OneMinuteRate,
             FiveMinuteRate = i.Value.FiveMinuteRate,
             FifteenMinuteRate = i.Value.FifteenMinuteRate,
             Percent = i.Percent
         }).ToArray(),
         Tags = meter.Tags
     };
 }
示例#2
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       = new TestReporter(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);
        }
示例#3
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);
        }
示例#4
0
        /// <inheritdoc />
        public IMeter Meter <T>(MeterOptions options, MetricTags tags, Func <T> builder)
            where T : IMeterMetric
        {
            var allTags    = AllTags(MetricTags.Concat(options.Tags, tags));
            var metricName = allTags.AsMetricName(options.Name);

            return(_meters.GetOrAdd(
                       metricName,
                       () =>
            {
                Logger.Trace("Adding Meter {Name} - {@Options} {MesurementUnit} {@Tags}", metricName, options, options.MeasurementUnit.ToString(), allTags.ToDictionary());

                var meter = builder();
                var valueSource = new MeterValueSource(
                    metricName,
                    meter,
                    options.MeasurementUnit,
                    options.RateUnit,
                    allTags,
                    options.ReportSetItems);
                return Tuple.Create((IMeter)meter, valueSource);
            }));
        }
示例#5
0
        public void 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
            AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), expected);
        }
示例#6
0
        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);
        }
示例#7
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       = CreateReporter(payloadBuilder);

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

            payloadBuilder.PayloadFormatted().
            Should().
            Be("test__test_meter host=server1 env=staging mtype=meter count.meter=1i rate1m=0 rate5m=0 rate15m=0" + Environment.NewLine);
        }
示例#8
0
        public async Task Can_report_meters_with_items()
        {
            // Arrange
            var expected =
                "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 1483232461000000000\ntest__test_meter__items,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,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",
                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);
        }
示例#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 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,host=server1,env=staging,mtype=meter,unit=none,unit_rate=ms count.meter=1i,rate1m=0,rate5m=0,rate15m=0\n");
        }
示例#10
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 items = CreateReporterAndPayloadBuilder();

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

            items.Item2.PayloadFormatted().
            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" + Environment.NewLine + "test__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" + Environment.NewLine + "test__test_meter host=server1 env=staging 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_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");
        }
        public static IEnumerable <Metric> ToPrometheusMetrics(
            this MeterValueSource metric,
            Func <string, string> labelNameFormatter)
        {
            var tags   = metric.Tags.ToLabelPairs(labelNameFormatter);
            var result = new List <Metric>
            {
                new Metric
                {
                    counter = new Counter
                    {
                        value = metric.Value.Count
                    },
                    label = tags
                }
            };

            if (metric.Value.Items?.Length > 0)
            {
                result.AddRange(metric.Value.Items.Select(x => x.ToPrometheusMetric(tags, labelNameFormatter)));
            }

            return(result);
        }
        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 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.host.server1.Total 1 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");
        }
示例#14
0
        public IEnumerable <MeterValueSource> SetupMeters()
        {
            var meterValue = new MeterValue(
                5,
                1,
                2,
                3,
                4,
                TimeUnit.Seconds,
                new[]
            {
                new MeterValue.SetItem("item", 0.5, new MeterValue(1, 2, 3, 4, 5, TimeUnit.Seconds, new MeterValue.SetItem[0]))
            });
            var meter = new MeterValueSource(MeterNameDefault, ConstantValue.Provider(meterValue), Unit.Calls, TimeUnit.Seconds, Tags);

            var meterValueWithGroup = new MeterValue(
                5,
                1,
                2,
                3,
                4,
                TimeUnit.Seconds,
                new[]
            {
                new MeterValue.SetItem("item", 0.5, new MeterValue(1, 2, 3, 4, 5, TimeUnit.Seconds, new MeterValue.SetItem[0]))
            });
            var meterWithGroup = new MeterValueSource(
                MeterNameWithGroup,
                GroupDefault,
                ConstantValue.Provider(meterValueWithGroup),
                Unit.Calls,
                TimeUnit.Seconds,
                Tags);

            return(new[] { meter, meterWithGroup });
        }
示例#15
0
        private IEnumerable <MetricTelemetry> TranslateMeterSource(MeterValueSource source, string contextName, DateTimeOffset now)
        {
            var unit = source.Value.RateUnit.ToShortString();

            if (source.ReportSetItems && source.Value.Items.Length > 0)
            {
                var dimensionName = GetDimensionName(source.Tags);
                foreach (var item in source.Value.Items)
                {
                    var mt = MetricFactory.CreateMetric(source, contextName, now);
                    TranslateTags(source.Tags, mt);
                    TranslateTags(item.Tags, mt);
                    TranslateMeterItem(item, mt, unit, dimensionName, Constants.MeterTypeValue);
                    yield return(mt);
                }
            }
            else
            {
                var mt = MetricFactory.CreateMetric(source, contextName, now);
                TranslateTags(source.Tags, mt);
                TranslateMeterValue(source.Value, mt, unit, Constants.MeterTypeValue);
                yield return(mt);
            }
        }
示例#16
0
 /// <inheritdoc />
 public bool IsMeterMatch(MeterValueSource meter)
 {
     return(true);
 }
 public MeterSerializationTests(ITestOutputHelper output, MetricProviderTestFixture fixture)
 {
     _output     = output;
     _serializer = new MetricDataSerializer();
     _meter      = fixture.Meters.First(x => x.Name == fixture.MeterNameDefault);
 }
 public bool IsMatch(MeterValueSource meter)
 {
     return(false);
 }
 private static IEnumerable<Google.ICanReportToGoogleAnalytics> Map(MeterValueSource meter, string context)
 {
     return new Google.Meter(FullName(meter.Name, context), meter.Unit.Name, string.Format("{0}/{1}", meter.Unit.Name, TimeUnitLabel(meter.RateUnit)), meter.Value.Count, meter.Value.MeanRate);
 }
示例#20
0
        public void Write(StreamWriter streamWriter, MetricsContextValueSource metricContext, MeterValueSource metric)
        {
            WriteMetricName(streamWriter, metric.MultidimensionalName);

            var value    = metric.ValueProvider.GetValue(metric.ResetOnReporting);
            var fullName = GetMetricRow(metricContext.Context, metric.MultidimensionalName, metric.Tags);

            streamWriter.WriteLine($"{fullName} {value.Count.ToString(CultureInfo.InvariantCulture)}");
        }
示例#21
0
 public bool IsMatch(MeterValueSource meter)
 {
     if (types != null && !types.Contains(MetricType.Meter))
     {
         return false;
     }
     return IsNameMatch(meter.Name);
 }
示例#22
0
 public bool IsMatch(MeterValueSource meter) { return true; }
 private static IEnumerable <Google.ICanReportToGoogleAnalytics> Map(MeterValueSource meter, string context)
 {
     return(new Google.Meter(FullName(meter.Name, context), meter.Unit.Name, string.Format("{0}/{1}", meter.Unit.Name, TimeUnitLabel(meter.RateUnit)), meter.Value.Count, meter.Value.MeanRate));
 }