Ejemplo n.º 1
0
        public void AddMetricsToEngine_OneUnscopedMetricNull()
        {
            var metric1 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", null,
                                                      MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(2)));

            Assert.That(metric1, Is.Not.Null);
            var data = metric1.Data;

            Assert.NotNull(data);
            Assert.AreEqual(1, data.Value0);
            Assert.AreEqual(3, data.Value1);
            Assert.AreEqual(2, data.Value2);

            var engine = new MetricStatsCollection();

            metric1.AddMetricsToEngine(engine);

            var stats = engine.ConvertToJsonForSending(_metricNameService);

            foreach (var current in stats)
            {
                Assert.AreEqual("DotNet/name", current.MetricName.Name);
                Assert.AreEqual(null, current.MetricName.Scope);
                var myData = current.Data;
                Assert.AreEqual(1, myData.Value0);
                Assert.AreEqual(3, myData.Value1);
                Assert.AreEqual(2, myData.Value2);
            }
        }
 /// <summary>
 /// Aggregates two metric data wire models together. Always create a new one because
 /// we reuse some of the same wire models.
 /// </summary>
 /// <param name="metric0">Data to be aggregated.</param>
 /// <param name="metric1">Data to be aggregated.</param>
 /// <returns></returns>
 public static MetricDataWireModel BuildAggregateData(MetricDataWireModel metric0, MetricDataWireModel metric1)
 {
     return(new MetricDataWireModel(
                (metric0.Value0 + metric1.Value0),
                (metric0.Value1 + metric1.Value1),
                (metric0.Value2 + metric1.Value2),
                (Math.Min(metric0.Value3, metric1.Value3)),
                (Math.Max(metric0.Value4, metric1.Value4)),
                (metric0.Value5 + metric1.Value5)));
 }
Ejemplo n.º 3
0
        public void BuildMemoryWorkingSetMetric()
        {
            const int RawBytes     = 1536;
            var       actualMetric = _metricBuilder.TryBuildMemoryWorkingSetMetric(RawBytes);

            NrAssert.Multiple(
                () => Assert.AreEqual(MetricNames.MemoryWorkingSet, actualMetric.MetricName.Name),
                () => Assert.AreEqual(MetricDataWireModel.BuildByteData(RawBytes), actualMetric.Data)
                );
        }
Ejemplo n.º 4
0
        public void BuildSupportabilityCountMetric_SuppliedCount()
        {
            const string MetricName   = "WCFClient/BindingType/BasicHttpBinding";
            var          actualMetric = _metricBuilder.TryBuildSupportabilityCountMetric(MetricName, 2);

            NrAssert.Multiple(
                () => Assert.AreEqual(MetricNames.GetSupportabilityName(MetricName), actualMetric.MetricName.Name),
                () => Assert.AreEqual(MetricDataWireModel.BuildCountData(2), actualMetric.Data)
                );
        }
Ejemplo n.º 5
0
        public void BuildGCBytesMetric()
        {
            const long RawByteValue = 123456;
            var        gcSampleType = Samplers.GCSampleType.Gen0Size;
            var        actualMetric = _metricBuilder.TryBuildGCBytesMetric(gcSampleType, RawByteValue);

            NrAssert.Multiple(
                () => Assert.AreEqual(MetricNames.GetGCMetricName(gcSampleType), actualMetric.MetricName.Name),
                () => Assert.AreEqual(MetricDataWireModel.BuildByteData(RawByteValue), actualMetric.Data)
                );
        }
Ejemplo n.º 6
0
        public void BuildThreadpoolThroughputStatsMetric()
        {
            const int RawValue            = 3;
            var       throughputStatsType = Samplers.ThreadpoolThroughputStatsType.Started;
            var       actualMetric        = _metricBuilder.TryBuildThreadpoolThroughputStatsMetric(throughputStatsType, RawValue);

            NrAssert.Multiple(
                () => Assert.AreEqual(MetricNames.GetThreadpoolThroughputStatsName(throughputStatsType), actualMetric.MetricName.Name),
                () => Assert.AreEqual(MetricDataWireModel.BuildGaugeValue(RawValue), actualMetric.Data)
                );
        }
Ejemplo n.º 7
0
        public void BuildGCCountMetric()
        {
            const int RawCountValue = 3;
            var       gcSampleType  = Samplers.GCSampleType.Gen0CollectionCount;
            var       actualMetric  = _metricBuilder.TryBuildGCCountMetric(gcSampleType, RawCountValue);

            NrAssert.Multiple(
                () => Assert.AreEqual(MetricNames.GetGCMetricName(gcSampleType), actualMetric.MetricName.Name),
                () => Assert.AreEqual(MetricDataWireModel.BuildCountData(RawCountValue), actualMetric.Data)
                );
        }
Ejemplo n.º 8
0
        public void BuildGCPercentMetric()
        {
            const float RawPercentageValue = 0.8f;
            var         gcSampleType       = Samplers.GCSampleType.PercentTimeInGc;
            var         actualMetric       = _metricBuilder.TryBuildGCPercentMetric(gcSampleType, RawPercentageValue);

            NrAssert.Multiple(
                () => Assert.AreEqual(MetricNames.GetGCMetricName(gcSampleType), actualMetric.MetricName.Name),
                () => Assert.AreEqual(MetricDataWireModel.BuildPercentageData(RawPercentageValue), actualMetric.Data)
                );
        }
Ejemplo n.º 9
0
        public void Merge_Throws_IfGivenMetricsWithDifferentNames()
        {
            var metric1 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", "scope",
                                                      MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(1)));
            var metric2 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name1", "scope",
                                                      MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(7), TimeSpan.FromSeconds(5)));
            var metric3 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name2", "scope",
                                                      MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(13), TimeSpan.FromSeconds(11)));

            NrAssert.Throws <Exception>(() => MetricWireModel.Merge(new[] { metric1, metric2, metric3 }));
        }
Ejemplo n.º 10
0
        public void BuildGCGaugeMetric()
        {
            const float RawValue     = 3000f;
            var         gcSampleType = Samplers.GCSampleType.HandlesCount;
            var         actualMetric = _metricBuilder.TryBuildGCGaugeMetric(gcSampleType, RawValue);

            NrAssert.Multiple(
                () => Assert.AreEqual(MetricNames.GetGCMetricName(gcSampleType), actualMetric.MetricName.Name),
                () => Assert.AreEqual(MetricDataWireModel.BuildGaugeValue(RawValue), actualMetric.Data)
                );
        }
Ejemplo n.º 11
0
        public void BuildThreadpoolUsageStatsMetric()
        {
            const int RawValue     = 3;
            var       threadType   = Samplers.ThreadType.Worker;
            var       threadStatus = Samplers.ThreadStatus.Available;
            var       actualMetric = _metricBuilder.TryBuildThreadpoolUsageStatsMetric(threadType, threadStatus, RawValue);

            NrAssert.Multiple(
                () => Assert.AreEqual(MetricNames.GetThreadpoolUsageStatsName(threadType, threadStatus), actualMetric.MetricName.Name),
                () => Assert.AreEqual(MetricDataWireModel.BuildGaugeValue(RawValue), actualMetric.Data)
                );
        }
Ejemplo n.º 12
0
        public void BuildAggregateData()
        {
            var one    = MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(4));
            var two    = MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(7), TimeSpan.FromSeconds(2));
            var actual = MetricDataWireModel.BuildAggregateData(one, two);

            Assert.AreEqual(2, actual.Value0);
            Assert.AreEqual(12, actual.Value1);
            Assert.AreEqual(6, actual.Value2);
            Assert.AreEqual(5, actual.Value3);
            Assert.AreEqual(7, actual.Value4);
            Assert.AreEqual(one.Value5 + two.Value5, actual.Value5);
        }
Ejemplo n.º 13
0
        public void BuildGaugeMetric()
        {
            const int expectedValue = 21;

            var metricData = MetricDataWireModel.BuildGaugeValue(expectedValue);

            NrAssert.Multiple(
                () => Assert.AreEqual(1, metricData.Value0),
                () => Assert.AreEqual(expectedValue, metricData.Value1),
                () => Assert.AreEqual(expectedValue, metricData.Value2),
                () => Assert.AreEqual(expectedValue, metricData.Value3),
                () => Assert.AreEqual(expectedValue, metricData.Value4),
                () => Assert.AreEqual(expectedValue * expectedValue, metricData.Value5)
                );
        }
Ejemplo n.º 14
0
        public void AddMetricsToEngine_OneScopedMetric()
        {
            var metric1 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", "scope",
                                                      MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(2)));

            Assert.That(metric1, Is.Not.Null);
            var data = metric1.Data;

            Assert.NotNull(data);
            Assert.AreEqual(1, data.Value0);
            Assert.AreEqual(3, data.Value1);
            Assert.AreEqual(2, data.Value2);

            var engine = new MetricStatsCollection();

            metric1.AddMetricsToEngine(engine);

            var actual        = engine.ConvertToJsonForSending(_metricNameService);
            var unscopedCount = 0;
            var scopedCount   = 0;
            var theScope      = string.Empty;
            var metricName    = string.Empty;
            MetricDataWireModel scopedData = null;

            foreach (var current in actual)
            {
                if (current.MetricName.Scope == null)
                {
                    unscopedCount++;
                }
                else
                {
                    scopedCount++;
                    theScope   = current.MetricName.Scope;
                    metricName = current.MetricName.Name;
                    scopedData = current.Data;
                }
            }

            Assert.AreEqual(1, scopedCount);
            Assert.AreEqual(0, unscopedCount);
            Assert.AreEqual("scope", theScope);
            Assert.AreEqual("DotNet/name", metricName);
            Assert.IsNotNull(scopedData);
            Assert.AreEqual(1, scopedData.Value0);
            Assert.AreEqual(3, scopedData.Value1);
            Assert.AreEqual(2, scopedData.Value2);
        }
Ejemplo n.º 15
0
        public void Merge_MergesOneMetricCorrectly()
        {
            var metric1 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", "scope",
                                                      MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(1)));
            var mergedMetric = MetricWireModel.Merge(new[] { metric1 });

            NrAssert.Multiple(
                () => Assert.AreEqual("DotNet/name", mergedMetric.MetricName.Name),
                () => Assert.AreEqual(1, mergedMetric.Data.Value0),
                () => Assert.AreEqual(3, mergedMetric.Data.Value1),
                () => Assert.AreEqual(1, mergedMetric.Data.Value2),
                () => Assert.AreEqual(3, mergedMetric.Data.Value3),
                () => Assert.AreEqual(3, mergedMetric.Data.Value4),
                () => Assert.AreEqual(9, mergedMetric.Data.Value5)
                );
        }
Ejemplo n.º 16
0
        public void BuildSummaryMetric()
        {
            const int count      = 18;
            const int value      = 20;
            const int min        = 10;
            const int max        = 30;
            const int sumSquares = value * value;

            var metricData = MetricDataWireModel.BuildSummaryValue(count, value, min, max);

            NrAssert.Multiple(
                () => Assert.AreEqual(count, metricData.Value0),
                () => Assert.AreEqual(value, metricData.Value1),
                () => Assert.AreEqual(value, metricData.Value2),
                () => Assert.AreEqual(min, metricData.Value3),
                () => Assert.AreEqual(max, metricData.Value4),
                () => Assert.AreEqual(sumSquares, metricData.Value5)
                );
        }
Ejemplo n.º 17
0
        public void Merge_MergesThreeMetricsCorrectly_WhenMergedProgressively()
        {
            var metric1 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", "scope",
                                                      MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(1)));
            var metric2 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", "scope",
                                                      MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(7), TimeSpan.FromSeconds(5)));
            var metric3 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", "scope",
                                                      MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(13), TimeSpan.FromSeconds(11)));

            var mergedMetric = MetricWireModel.Merge(new[] { metric1, metric2 });

            mergedMetric = MetricWireModel.Merge(new[] { mergedMetric, metric3 });

            NrAssert.Multiple(
                () => Assert.AreEqual("DotNet/name", mergedMetric.MetricName.Name),
                () => Assert.AreEqual(3, mergedMetric.Data.Value0),
                () => Assert.AreEqual(23, mergedMetric.Data.Value1),
                () => Assert.AreEqual(17, mergedMetric.Data.Value2),
                () => Assert.AreEqual(3, mergedMetric.Data.Value3),
                () => Assert.AreEqual(13, mergedMetric.Data.Value4),
                () => Assert.AreEqual(227, mergedMetric.Data.Value5)
                );
        }
Ejemplo n.º 18
0
        public void MetricWireModel_SerializesCorrectlyUnscoped()
        {
            const string expectedJson = @"[{""name"":""DotNet/name""},[1,3.0,1.0,3.0,3.0,9.0]]";

            var metric1 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", null, MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(1)));

            var serializedMetric = JsonConvert.SerializeObject(metric1);

            Assert.AreEqual(expectedJson, serializedMetric);
        }