예제 #1
0
        public void SimpleHistogramUsageExample()
        {
            TelemetryConfiguration configuraiton = new TelemetryConfiguration();

            TelemetryClient client = new TelemetryClient(configuraiton);

            client.Context.Properties["a"] = "b";

            var simpleMeter = client.Histogram("test");
            var counters    = configuraiton.GetCounters();

            Assert.AreEqual(1, counters.Count);

            for (int i = 0; i < 10; i++)
            {
                simpleMeter.Update(i);
            }

            MetricTelemetry metric = counters[0].GetValueAndReset();

            Assert.AreEqual(9 * (9 + 1) / 2 / 10.0, metric.Value);
            Assert.AreEqual(10, metric.Count);
            Assert.AreEqual(0, metric.Min);
            Assert.AreEqual(9, metric.Max);
            Assert.AreEqual("test", metric.Name);
            Assert.AreEqual("b", metric.Context.Properties["a"]);
        }
예제 #2
0
        public void HistogramPercentilesExample()
        {
            TelemetryConfiguration configuration = new TelemetryConfiguration();

            TelemetryClient client = new TelemetryClient(configuration);

            var histogramWithPercentiles = client.Histogram("test", HistogramAggregations.Percentiles);

            for (int i = 1; i <= 1000; i++)
            {
                histogramWithPercentiles.Update(i);
            }

            var counters = configuration.GetCounters();

            MetricTelemetry metric = counters[0].GetValueAndReset();

            Assert.AreEqual(5, metric.Properties.Count);
            Assert.AreEqual(true, metric.Properties["p50"].Equals("500"));
            Assert.AreEqual(true, metric.Properties["p75"].Equals("750"));
            Assert.AreEqual(true, metric.Properties["p90"].Equals("900"));
            Assert.AreEqual(true, metric.Properties["p95"].Equals("950"));
            Assert.AreEqual(true, metric.Properties["p99"].Equals("990"));
        }