public void BuildGaugeMetric()
        {
            var timestamp = DateTime.UtcNow;
            var interval  = 33L;
            var value     = 87;

            var attributes = new Dictionary <string, object>
            {
                { "attrKey", "attrValue" }
            };

            var metricBuilder = MetricBuilder.CreateGaugeMetric("metricname")
                                .WithValue(value)
                                .WithTimestamp(timestamp)
                                .WithIntervalMs(interval)
                                .WithAttribute("adsfasdf", 12)
                                .WithAttributes(attributes);

            var metric = metricBuilder.Build();

            Assert.AreEqual("metricname", metric.Name);
            Assert.AreEqual("gauge", metric.Type);
            Assert.AreEqual(value, ((GaugeMetric)metric).Value);
            Assert.AreEqual(DateTimeExtensions.ToUnixTimeMilliseconds(timestamp), metric.Timestamp);
            Assert.AreEqual(interval, metric.IntervalMs);
            Assert.AreEqual(12, metric.Attributes["adsfasdf"]);
            Assert.AreEqual("attrValue", metric.Attributes["attrKey"]);
        }
Пример #2
0
        public void MetricBatchWithCommonPropertiesAndMetrics()
        {
            var timestamp   = DateTime.UtcNow;
            var interval    = 125L;
            var commonAttrs = new Dictionary <string, object>()
            {
                { "attr1Key", "attr1Value" }
            };
            var countValue = 88d;
            var gaugeValue = 213d;

            var metricBatch = MetricBatchBuilder.Create()
                              .WithTimestamp(timestamp)
                              .WithIntervalMs(interval)
                              .WithAttributes(commonAttrs)
                              .WithMetric(MetricBuilder.CreateCountMetric("CountMetric")
                                          .WithValue(countValue)
                                          .Build())
                              .WithMetric(MetricBuilder.CreateGaugeMetric("GaugeMetric")
                                          .WithValue(gaugeValue)
                                          .Build())
                              .Build();

            Assert.AreEqual(DateTimeExtensions.ToUnixTimeMilliseconds(timestamp), metricBatch.CommonProperties.Timestamp, $"MetricBatch CommonProperties [Timestamp] - expected: {timestamp}, actual: {metricBatch.CommonProperties.Timestamp}");
            Assert.AreEqual(interval, metricBatch.CommonProperties.IntervalMs, $"MetricBatch CommonProperties [IntervalMs] - expected: {interval}, actual: {metricBatch.CommonProperties.IntervalMs}");

            Assert.AreEqual(2, metricBatch.Metrics.Count, $"MetricBatch Metrics count - expected: 2, actual: {metricBatch.Metrics.Count}");
            Assert.AreEqual("count", metricBatch.Metrics[0].Type, $"MetricBatch Metrics[0].Type - expected: count, actual: {metricBatch.Metrics[0].Type}");
            Assert.AreEqual("gauge", metricBatch.Metrics[1].Type, $"MetricBatch Metrics[1].Type - expected: gauge, actual: {metricBatch.Metrics[1].Type}");
        }
        public void SendANonEmptyMetricBatch()
        {
            var metricBatch = MetricBatchBuilder.Create()
                              .WithMetric(MetricBuilder.CreateGaugeMetric("TestMetric").Build())
                              .Build();

            var dataSender = new MetricDataSender(new TelemetryConfiguration().WithApiKey("123456"));

            dataSender.WithHttpHandlerImpl((serializedJson) =>
            {
                var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
                return(Task.FromResult(response));
            });

            var response = dataSender.SendDataAsync(metricBatch).Result;

            Assert.AreEqual(NewRelicResponseStatus.Success, response.ResponseStatus);
        }
Пример #4
0
        public void MetricBatchWithNoCommonElement()
        {
            var timestamp    = DateTime.UtcNow;
            var interval     = 125L;
            var gaugeValue   = 213d;
            var summaryValue = MetricSummaryValue.Create(10d, 64, 3, 15);

            var metricBatch = MetricBatchBuilder.Create()
                              .WithMetric(MetricBuilder.CreateSummaryMetric("SummaryMetric")
                                          .WithTimestamp(timestamp)
                                          .WithIntervalMs(interval)
                                          .WithValue(summaryValue)
                                          .Build())
                              .WithMetric(MetricBuilder.CreateGaugeMetric("GaugeMetric")
                                          .WithTimestamp(timestamp)
                                          .WithIntervalMs(interval)
                                          .WithValue(gaugeValue)
                                          .Build())
                              .Build();

            Assert.AreEqual(2, metricBatch.Metrics.Count, $"MetricBatch Metrics count - expected: 2, actual: {metricBatch.Metrics.Count}");
            Assert.IsNull(metricBatch.CommonProperties, $"MetricBatch CommonProperties - expected: null, actual: not null");
        }