コード例 #1
0
        public void MetricBatchAllowsCommonAndSpecificSameNamedFields()
        {
            var currentUtcTime  = DateTimeOffset.UtcNow;
            var commonTimestamp = currentUtcTime.ToUnixTimeMilliseconds();
            var commonInterval  = 125L;

            var metricTimestamp = currentUtcTime.AddMinutes(1).ToUnixTimeMilliseconds();
            var metricInterval  = 312L;

            var countValue = 88d;

            var metricBatch = new NewRelicMetricBatch(
                commonProperties: new NewRelicMetricBatchCommonProperties(
                    timestamp: commonTimestamp,
                    intervalMs: commonInterval,
                    attributes: new Dictionary <string, object>
            {
                { "Attr1Key", "comAttr1Value" },
            }),
                metrics: new[]
            {
                NewRelicMetric.CreateCountMetric(
                    name: "CountMetric",
                    timestamp: metricTimestamp,
                    attributes: new Dictionary <string, object>()
                {
                    { "Attr1Key", "metAttr1Value" },
                },
                    value: countValue,
                    intervalMs: metricInterval),
            });

            var actualMetrics = metricBatch.Metrics.ToArray();

            Assert.Equal(commonTimestamp, metricBatch.CommonProperties.Timestamp);
            Assert.Equal(commonInterval, metricBatch.CommonProperties.IntervalMs);
            Assert.Equal("comAttr1Value", metricBatch.CommonProperties.Attributes["Attr1Key"]);

            Assert.Equal(metricTimestamp, actualMetrics[0].Timestamp);
            Assert.Equal(metricInterval, actualMetrics[0].IntervalMs);
            Assert.Equal("metAttr1Value", actualMetrics[0].Attributes?["Attr1Key"]);
        }
コード例 #2
0
        public void MetricBatchWithCommonPropertiesAndMetrics()
        {
            var timestamp   = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            var interval    = 125L;
            var commonAttrs = new Dictionary <string, object>()
            {
                { "attr1Key", "attr1Value" }
            };
            var countValue = 88d;
            var gaugeValue = 213d;

            var metricBatch = new NewRelicMetricBatch(
                commonProperties: new NewRelicMetricBatchCommonProperties(
                    timestamp: timestamp,
                    intervalMs: interval,
                    attributes: new Dictionary <string, object>()
            {
                { "attr1Key", "attr1Value" },
            }),
                metrics: new[]
            {
                NewRelicMetric.CreateCountMetric(
                    name: "CountMetric",
                    timestamp: null,
                    attributes: null,
                    value: countValue,
                    intervalMs: interval),
                NewRelicMetric.CreateGaugeMetric(
                    name: "GaugeMetric",
                    timestamp: null,
                    attributes: null,
                    value: gaugeValue),
            });

            var actualMetrics = metricBatch.Metrics.ToArray();

            Assert.Equal(timestamp, metricBatch.CommonProperties.Timestamp);
            Assert.Equal(interval, metricBatch.CommonProperties.IntervalMs);
            Assert.Equal(2, actualMetrics.Length);
            Assert.Equal("count", actualMetrics[0].Type);
            Assert.Equal("gauge", actualMetrics[1].Type);
        }
コード例 #3
0
        public void BuildCountMetric()
        {
            var timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            var interval  = 33L;
            var value     = 22;

            var metric = NewRelicMetric.CreateCountMetric(
                name: "metricName",
                timestamp: timestamp,
                attributes: new Dictionary <string, object>
            {
                { "attrKey", "attrValue" },
                { "adsfasdf", 12 },
            },
                value: value,
                intervalMs: interval);

            Assert.Equal("metricName", metric.Name);
            Assert.Equal("count", metric.Type);
            Assert.Equal(value, metric.Value);
            Assert.Equal(timestamp, metric.Timestamp);
            Assert.Equal(interval, metric.IntervalMs);
            Assert.Equal("attrValue", metric.Attributes?["attrKey"]);
        }
コード例 #4
0
        public void ToJson_NonEmptyMetricBatch()
        {
            // Arrange
            var metricBatch = new NewRelicMetricBatch(
                commonProperties: new NewRelicMetricBatchCommonProperties(
                    timestamp: _timestampL,
                    intervalMs: _interval,
                    attributes: null),
                metrics: new[]
            {
                NewRelicMetric.CreateCountMetric(
                    name: "metric1",
                    timestamp: null,
                    attributes: _customAttributes,
                    value: _countValue,
                    intervalMs: _interval),
                NewRelicMetric.CreateSummaryMetric(
                    name: "metric2",
                    timestamp: null,
                    attributes: null,
                    interval: _interval,
                    summaryValue: _summaryValue),
            });

            // Act
            var jsonString = metricBatch.ToJson();

            // Assert
            var resultMetricBatches = TestHelpers.DeserializeArray(jsonString);

            TestHelpers.AssertForCollectionLength(resultMetricBatches, 1);

            // CountMetric
            var resultMetricBatch = resultMetricBatches.First();
            var resultCommonProps = TestHelpers.DeserializeObject(resultMetricBatch["common"]);

            TestHelpers.AssertForAttribValue(resultCommonProps, "timestamp", _timestampL);
            TestHelpers.AssertForAttribValue(resultCommonProps, "interval.ms", _interval);

            var resultMetrics = TestHelpers.DeserializeArray(resultMetricBatch["metrics"]);

            TestHelpers.AssertForCollectionLength(resultMetrics, 2);

            var countMetric = resultMetrics.First();

            TestHelpers.AssertForAttribCount(countMetric, 5);

            TestHelpers.AssertForAttribValue(countMetric, "name", "metric1");
            TestHelpers.AssertForAttribValue(countMetric, "type", "count");
            TestHelpers.AssertForAttribValue(countMetric, "value", _countValue);
            TestHelpers.AssertForAttribValue(countMetric, "interval.ms", _interval);

            var countMetricAttribs = TestHelpers.DeserializeObject(countMetric["attributes"]);

            TestHelpers.AssertForAttribCount(countMetricAttribs, 1);
            TestHelpers.AssertForAttribValue(countMetricAttribs, "attr1Key", "attr1Value");

            // SummaryMetric
            var summaryMetric = resultMetrics[1];

            TestHelpers.AssertForAttribCount(summaryMetric, 4);

            TestHelpers.AssertForAttribValue(summaryMetric, "name", "metric2");
            TestHelpers.AssertForAttribValue(summaryMetric, "type", "summary");
            TestHelpers.AssertForAttribValue(summaryMetric, "value", _summaryValue);
            TestHelpers.AssertForAttribValue(countMetric, "interval.ms", _interval);
        }