public void FlushedMetricDoesNotHaveData()
        {
            var collector = new MetricsCollector();

            collector.Record("counter", 10M, Unit.Minute);

            collector.FlushToString();

            Assert.Equal(string.Empty, collector.GetMetrics()["counter"].FlushToString());
        }
        public void TestRecorders()
        {
            var collector = new MetricsCollector();

            collector.Record("Recorder1", 1.0M, Unit.MilliSecond);
            collector.Record("Recorder1", 11.0M, Unit.MilliSecond);
            collector.Record("Recorder2", 2.0M, Unit.Second);
            collector.Record("Recorder2", 22.0M, Unit.Second);

            var metrics = collector.GetMetrics();

            Assert.Equal(2, metrics.Count);
            RecorderUtils.AssertRecorderOutput(new[] { 1.0M, 11.0M }, Unit.MilliSecond,
                                               metrics["Recorder1"].FlushToString());
            RecorderUtils.AssertRecorderOutput(new[] { 2.0M, 22.0M }, Unit.Second, metrics["Recorder2"].FlushToString());
        }
        public void TestCounters()
        {
            var          collector = new MetricsCollector();
            const string numOfExceptionsMetricName = "NumOfExceptions";
            const string succeededMetricName       = "Succeeded";

            collector.IncrementCounter(numOfExceptionsMetricName, 0);
            collector.IncrementCounter(numOfExceptionsMetricName, 1);
            collector.IncrementCounter(succeededMetricName, 1);
            collector.IncrementCounter(succeededMetricName, 2);

            var metrics = collector.GetMetrics();

            Assert.Equal(2, metrics.Count);
            Assert.Equal("1", metrics[numOfExceptionsMetricName].FlushToString());
            Assert.Equal("3", metrics[succeededMetricName].FlushToString());
        }
        public async Task TestStartStopTimers()
        {
            var collector = new MetricsCollector();

            using (collector.StartTimer("Clock1"))
            {
                await Task.Delay(100);
            }

            using (collector.StartTimer("Clock2"))
            {
                await Task.Delay(200);
            }

            var metrics = collector.GetMetrics();

            Assert.Equal(2, metrics.Count);
            RecorderUtils.AssertRecorderOutput(new[] { 100.0M }, Unit.MilliSecond, metrics["Clock1"].FlushToString(),
                                               10.0M);
            RecorderUtils.AssertRecorderOutput(new[] { 200.0M }, Unit.MilliSecond, metrics["Clock2"].FlushToString(),
                                               10.0M);
        }