public NancyAdapterGlobalMetrics() { this.clock = new TestClock(); this.scheduler = new TestScheduler(clock); this.timer = new TimerMetric(SamplingType.SlidingWindow, new MeterMetric(clock, scheduler), clock); this.meter = new MeterMetric(clock, scheduler); this.counter = new CounterMetric(); this.size = new HistogramMetric(); this.browser = new Browser(with => { with.ApplicationStartup((c, p) => { Metric.Config.WithNancy(new TestRegistry { TimerInstance = timer, MeterInstance = meter, CounterInstance = counter, HistogramInstance = size }, nancy => nancy.WithGlobalMetrics(config => config.RegisterAllMetrics(p))); }); with.Module(new TestModule(this.clock)); with.Module(new ActiveRequestsModule(this.requestTrigger.Task, result1, result2)); }); }
public void HistogramMetric_should_flatten_and_return_itself() { Distribution distribution = new Distribution( new Dictionary <string, DistributionValue> { { "a", new DistributionValue(6, .6) }, { "b", new DistributionValue(4, .4) } }, 2); HistogramMetric metric = new HistogramMetric("instance-name", Try <Distribution> .From(() => distribution)); List <DoubleMetric> expected = new List <DoubleMetric> { new DoubleMetric(MetricEntity.Column, "Histogram.bins", "instance-name", Try <double> .From(() => 2)), new DoubleMetric(MetricEntity.Column, "Histogram.abs.a", "instance-name", Try <double> .From(() => 6)), new DoubleMetric(MetricEntity.Column, "Histogram.abs.b", "instance-name", Try <double> .From(() => 4)), new DoubleMetric(MetricEntity.Column, "Histogram.ratio.a", "instance-name", Try <double> .From(() => .6)), new DoubleMetric(MetricEntity.Column, "Histogram.ratio.b", "instance-name", Try <double> .From(() => .4)) }; metric.Flatten().Any(flattenMetric => flattenMetric.Name == "Histogram.bins").ShouldBeTrue(); metric.Flatten().Any(flattenMetric => flattenMetric.Name == "Histogram.abs.a").ShouldBeTrue(); metric.Flatten().Any(flattenMetric => flattenMetric.Name == "Histogram.abs.b").ShouldBeTrue(); metric.Flatten().Any(flattenMetric => flattenMetric.Name == "Histogram.ratio.a").ShouldBeTrue(); metric.Flatten().Any(flattenMetric => flattenMetric.Name == "Histogram.ratio.b").ShouldBeTrue(); }
public void can_add_histgoram_values() { var histogramMetric = new HistogramMetric(SamplingType.ExponentiallyDecaying, 1028, 0.015); histogramMetric.Update(10000, "value"); var values = new Dictionary <string, object>(); histogramMetric.Value.AddHistogramValues(values); values.Keys.Should().Contain("samples"); values.Keys.Should().Contain("last"); values.Keys.Should().Contain("count.hist"); values.Keys.Should().Contain("min"); values.Keys.Should().Contain("max"); values.Keys.Should().Contain("mean"); values.Keys.Should().Contain("median"); values.Keys.Should().Contain("stddev"); values.Keys.Should().Contain("p999"); values.Keys.Should().Contain("p99"); values.Keys.Should().Contain("p98"); values.Keys.Should().Contain("p95"); values.Keys.Should().Contain("p75"); values.Keys.Should().Contain("user.last"); values.Keys.Should().Contain("user.min"); values.Keys.Should().Contain("user.max"); }
public void HistogramCanCount() { var histogram = new HistogramMetric(new UniformReservoir()); histogram.Update(1L); histogram.Value.Count.Should().Be(1); histogram.Update(1L); histogram.Value.Count.Should().Be(2); }
public void SampleMin_WhenPassed8And9_Returns8() { var underTest = new HistogramMetric(HistogramMetric.SampleType.Uniform); underTest.Update(9); underTest.Update(8); Assert.AreEqual(8, underTest.SampleMin); }
public void Count_WhenPassedTwoValues_Returns2() { var underTest = new HistogramMetric(HistogramMetric.SampleType.Uniform); underTest.Update(9); underTest.Update(8); Assert.AreEqual(2, underTest.Count); }
public void Max_WhenPassed8And9_Returns9() { var underTest = new HistogramMetric(HistogramMetric.SampleType.Uniform); underTest.Update(9); underTest.Update(8); Assert.AreEqual(9, underTest.Max); }
public void Mean_WhenPassed8And9_Returns8Point5() { var underTest = new HistogramMetric(HistogramMetric.SampleType.Uniform); underTest.Update(9); underTest.Update(8); Assert.AreEqual(8.5, underTest.Mean); }
public void SampleMin_UsesSample() { var underTest = new HistogramMetric(new RejectEverythingAboveTenSample()); underTest.Update(11); underTest.Update(12); Assert.AreEqual(0, underTest.SampleMin); }
public DiskPerformanceStorage() { WriteLatencyHistogram = new HistogramMetric(HistogramMetric.SampleType.Uniform); ReadLatencyHistogram = new HistogramMetric(HistogramMetric.SampleType.Uniform); ReadPerSecondHistory = new List <long>(); WritePerSecondHistory = new List <long>(); AverageReadLatencyPerSecondHistory = new List <double>(); AverageWriteLatencyPerSecondHistory = new List <double>(); }
public void BiasedHistogram_UsesSample() { var underTest = new HistogramMetric(HistogramMetric.SampleType.Biased); var sampleSize = 1028; var sample = Enumerable.Range(1, sampleSize).ToList(); foreach (var s in sample) { underTest.Update(s); } Assert.AreEqual(sampleSize, underTest.SampleCount); CollectionAssert.AreEquivalent(sample, underTest.Values); }
public NancyAdapterModuleMetricsTests() { this.clock = new TestClock(); TestScheduler scheduler = new TestScheduler(clock); this.timer = new TimerMetric(SamplingType.SlidingWindow, new MeterMetric(clock, scheduler), clock); this.sizeHistogram = new HistogramMetric(); Metric.Config.WithNancy(new TestRegistry { TimerInstance = timer, HistogramInstance = sizeHistogram }, c => { }); this.browser = new Browser(with => { with.Module(new TestModule(this.clock)); }); }
public void can_report_histograms() { var expected = StringReporterSamples.Histograms.ExtractStringReporterSampleFromResourceFile(); var sr = new StringReporter(); var metric = new HistogramMetric(SamplingType.ExponentiallyDecaying, Constants.ReservoirSampling.DefaultSampleSize, Constants.ReservoirSampling.DefaultExponentialDecayFactor); metric.Update(1000, "value1"); metric.Update(2000, "value2"); sr.ReportMetric("test", new HistogramValueSource("histogram_name", metric, Unit.None, MetricTags.None)); AssertReportResult(sr.Result, expected); }
private static void WriteHistogram(StringBuilder sb, HistogramMetric histogram) { var percentiles = histogram.Percentiles(0.5, 0.75, 0.95, 0.98, 0.99, 0.999); sb.AppendFormat(" min = {0:F2}\n", histogram.Min); sb.AppendFormat(" max = {0:F2}\n", histogram.Max); sb.AppendFormat(" mean = {0:F2}\n", histogram.Mean); sb.AppendFormat(" stddev = {0:F2}\n", histogram.StdDev); sb.AppendFormat(" median = {0:F2}\n", percentiles[0]); sb.AppendFormat(" 75%% <= {0:F2}\n", percentiles[1]); sb.AppendFormat(" 95%% <= {0:F2}\n", percentiles[2]); sb.AppendFormat(" 98%% <= {0:F2}\n", percentiles[3]); sb.AppendFormat(" 99%% <= {0:F2}\n", percentiles[4]); sb.AppendFormat(" 99.9%% <= {0:F2}\n", percentiles[5]); }
private static void WriteHistogram(TextWriter writer, HistogramMetric histogram) { var percentiles = histogram.Percentiles(0.5, 0.75, 0.95, 0.98, 0.99, 0.999); writer.Write(" min = %{0:2}\n", histogram.Min); writer.Write(" max = %{0:2}\n", histogram.Max); writer.Write(" mean = %{0:2}\n", histogram.Mean); writer.Write(" stddev = %{0:2}\n", histogram.StdDev); writer.Write(" median = %{0:2}\n", percentiles[0]); writer.Write(" 75%% <= %{0:2}\n", percentiles[1]); writer.Write(" 95%% <= %{0:2}\n", percentiles[2]); writer.Write(" 98%% <= %{0:2}\n", percentiles[3]); writer.Write(" 99%% <= %{0:2}\n", percentiles[4]); writer.Write(" 99.9%% <= %{0:2}\n", percentiles[5]); }
static void Main(string[] args) { try { var metrics = new Metrics(); //DataDogReporterConfigModel dataDogReporterConfigModel = new DataDogReporterConfigModel("appdev", 8125, "ApplicationName", "DomainName", "Development"); ITransport transport = new UdpTransport.Builder().WithPort(8125) .WithStatsdHost("appdev") .Build(); string host = "hostName"; string environment = "testEnv"; string[] path = { "ApplicationName", "DomainName" }; //IMetricNameFormatter formatter = new AppendMetricNameToPathFormatter(); IMetricNameFormatter formatter = new AppendMetricNameToPathFormatter(); var reporter = new DataDogReporter(metrics, transport, formatter, environment, host, path); reporter.Start(5, TimeUnit.Seconds); CounterMetric counter = metrics.Counter("test", "CounterMetric"); HistogramMetric histogramMetric = metrics.Histogram("test", "HistogramMetric"); GaugeMetric gaugeMetric = metrics.Gauge("test", "GaugeMetric", GetNumberOfUsersLoggedIn); var rand = new Random(); int runs = 0; while (runs < 1000) { System.Console.WriteLine("Loop " + (runs++) + " of 1000"); counter.Increment(); counter.Increment(); counter.Increment(); histogramMetric.Update(rand.Next(100)); histogramMetric.Update(rand.Next(100)); histogramMetric.Update(rand.Next(100)); histogramMetric.Update(rand.Next(100)); histogramMetric.Update(rand.Next(100)); Thread.Sleep(5000); } } catch (Exception e) { throw; } }
public void MetricConverterTest() { var metrics = new Metrics(); CounterMetric counter = metrics.Counter("test", "CounterMetric"); HistogramMetric histogramMetric = metrics.Histogram("test", "HistogramMetric"); GaugeMetric gaugeMetric = metrics.Gauge("test", "GaugeMetric", GetNumberOfUsersLoggedIn); DataDogReporter reporter = CreateDefaultReporter(metrics); TestRequest request = new TestRequest(); reporter.TransformMetrics(request, metrics, 0); IDictionary <string, DatadogSeries> convertedMetrics = request.Metrics; Assert.AreEqual(12, convertedMetrics.Count); }
public void can_report_timers() { var expected = StringReporterSamples.Timers.ExtractStringReporterSampleFromResourceFile(); var sr = new StringReporter(); var clock = new TestClock(); var histogram = new HistogramMetric(SamplingType.ExponentiallyDecaying, Constants.ReservoirSampling.DefaultSampleSize, Constants.ReservoirSampling.DefaultExponentialDecayFactor); var metric = new TimerMetric(histogram, clock); metric.Record(1000, TimeUnit.Milliseconds, "value1"); metric.Record(2000, TimeUnit.Milliseconds, "value2"); sr.ReportMetric("test", new TimerValueSource("timer_name", metric, Unit.None, TimeUnit.Milliseconds, TimeUnit.Milliseconds, MetricTags.None)); AssertReportResult(sr.Result, expected); }
private void LogHistogram(IRequest request, MetricName metricName, HistogramMetric metric, long timestamp) { LogGauge(request, metricName.Name + "." + HistogramMetrics.Max.GetDatadogName(), metric.SampleMax, timestamp); LogGauge(request, metricName.Name + "." + HistogramMetrics.Min.GetDatadogName(), metric.SampleMin, timestamp); LogGauge(request, metricName.Name + "." + HistogramMetrics.Mean.GetDatadogName(), metric.SampleMean, timestamp); LogGauge(request, metricName.Name + "." + HistogramMetrics.StdDev.GetDatadogName(), metric.StdDev, timestamp); LogGauge(request, metricName.Name + "." + HistogramMetrics.Count.GetDatadogName(), metric.SampleCount, timestamp); double[] percentResults = metric.Percentiles(_histogramPercentages); LogGauge(request, metricName.Name + "." + HistogramMetrics.At75thPercentile.GetDatadogName(), percentResults[0], timestamp); LogGauge(request, metricName.Name + "." + HistogramMetrics.At95thPercentile.GetDatadogName(), percentResults[1], timestamp); LogGauge(request, metricName.Name + "." + HistogramMetrics.At98thPercentile.GetDatadogName(), percentResults[2], timestamp); LogGauge(request, metricName.Name + "." + HistogramMetrics.At99thPercentile.GetDatadogName(), percentResults[3], timestamp); LogGauge(request, metricName.Name + "." + HistogramMetrics.At999thPercentile.GetDatadogName(), percentResults[4], timestamp); metric.Clear(); }
public void can_report_histograms() { var metricsMock = new Mock <IMetrics>(); var histogram = new HistogramMetric(SamplingType.ExponentiallyDecaying, 1028, 0.015); histogram.Update(1000, "client1"); var histogramValueSource = new HistogramValueSource("test histogram", ConstantValue.Provider(histogram.Value), Unit.None, MetricTags.None); var payloadBuilder = new LineProtocolPayloadBuilder(); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", histogramValueSource); payloadBuilder.PayloadFormatted() .Should() .Be( "test__test_histogram samples=1i,last=1000,count.hist=1i,min=1000,max=1000,mean=1000,median=1000,stddev=0,p999=1000,p99=1000,p98=1000,p95=1000,p75=1000,user.last=\"client1\",user.min=\"client1\",user.max=\"client1\"\n"); }
public void HistogramPercentages() { Metrics metrics = new Metrics(); HistogramMetric histogramMetric = metrics.Histogram("test", "HealthMetrics.Test.HistogramMetrics"); for (int x = 1; x <= 100; x++) { histogramMetric.Update(x); } double[] percentials = { 0.75, 0.99, 0.999 }; double[] results = histogramMetric.Percentiles(percentials); Assert.IsNotNull(results); Assert.AreEqual(3, results.Length); Assert.AreEqual(75, results[0], 1); Assert.AreEqual(99, results[1], 1); Assert.AreEqual(99, results[2], 1); }
public static HistogramData GetHistogramData(this HistogramMetric histogram, double[] percentiles) { var percentileValues = histogram.Percentiles(percentiles); return(new HistogramData { Counter = histogram.Count, Max = histogram.Max, Mean = histogram.Mean, Min = histogram.Min, Stdev = histogram.StdDev, Percentiles = new Dictionary <string, double> { { string.Format("{0}%", percentiles[0]), percentileValues[0] }, { string.Format("{0}%", percentiles[1]), percentileValues[1] }, { string.Format("{0}%", percentiles[2]), percentileValues[2] }, { string.Format("{0}%", percentiles[3]), percentileValues[3] }, { string.Format("{0}%", percentiles[4]), percentileValues[4] }, { string.Format("{0}%", percentiles[5]), percentileValues[5] }, } }); }
private static HistogramData CreateHistogramData(HistogramMetric histogram) { double[] percentiles = histogram.Percentiles(0.5, 0.75, 0.95, 0.99, 0.999, 0.9999); return(new HistogramData { Counter = histogram.Count, Max = histogram.Max, Mean = histogram.Mean, Min = histogram.Min, Stdev = histogram.StdDev, Percentiles = new Dictionary <string, double> { { "50%", percentiles[0] }, { "75%", percentiles[1] }, { "95%", percentiles[2] }, { "99%", percentiles[3] }, { "99.9%", percentiles[4] }, { "99.99%", percentiles[5] }, } }); }
public void SingleHistogramTest() { var metrics = new Metrics(); string metricName = "HistogramrMetric"; HistogramMetric histogramMetric = metrics.Histogram("test", metricName); DataDogReporter reporter = CreateDefaultReporter(metrics); TestRequest request = new TestRequest(); reporter.TransformMetrics(request, metrics, 0); IDictionary <string, DatadogSeries> convertedMetrics = request.Metrics; Assert.AreEqual(10, convertedMetrics.Count); foreach (HistogramMetrics histoName in HistogramMetrics.AllMetrics) { DatadogSeries metric = convertedMetrics[APP + "." + DOMAIN + "." + metricName + "." + histoName.GetDatadogName()]; Assert.NotNull(metric); Assert.IsTrue(metric is DatadogGauge); ValidateDefaultTags(metric.Tags); } }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ private void SendData(object pState) { foreach (string path in vTimerPaths) { ManualTimerMetric mtm = Metrics.ManualTimer(GetType(), path, TimeUnit.Milliseconds, TimeUnit.Milliseconds); double[] perc = mtm.Percentiles(0.95, 0.99); vGraphite.Send(path + ".timer.mean", mtm.Mean); vGraphite.Send(path + ".timer.p95", perc[0]); vGraphite.Send(path + ".timer.p99", perc[1]); mtm.Clear(); } foreach (string path in vMeanPaths) { HistogramMetric hm = Metrics.Histogram(GetType(), path); vGraphite.Send(path + ".mean", hm.Mean); hm.Clear(); } foreach (string path in vCounterPaths) { CounterMetric cm = Metrics.Counter(GetType(), path); vGraphite.Send(path + ".counter", cm.Count); cm.Clear(); } foreach (string path in vGaugePaths) { GaugeMetric <long> gm = Metrics.Gauge <long>(GetType(), path, null); vGraphite.Send(path + ".gauge", gm.Value); } ResetPaths(); }
private static IReservoir GetReservoir(HistogramMetric histogram) { return(ReservoirField.GetValue(histogram) as IReservoir); }
public OwinMetricsTestData() { const int timePerRequest = 100; const string json = "{ 'id': '1'} "; Clock = new TestClock(); var scheduler = new TestScheduler(Clock); TimerMetric = new TimerMetric(SamplingType.SlidingWindow, new MeterMetric(Clock, scheduler), Clock); CounterMetric = new TestCounter(); HistogramMetric = new HistogramMetric(); MeterMetric = new MeterMetric(Clock, scheduler); var server = TestServer.Create(app => { var registery = new TestRegistry { TimerInstance = TimerMetric, CounterInstance = CounterMetric, HistogramInstance = HistogramMetric, MeterInstance = MeterMetric }; OwinMetricsConfig owin = new OwinMetricsConfig(middleware => app.Use(middleware), registery, Metric.Config.HealthStatus); owin.WithRequestMetricsConfig(c => c.RegisterAllMetrics()); app.Run(context => { Clock.Advance(TimeUnit.Milliseconds, timePerRequest); if (context.Request.Path.ToString() == "/test/action") { return context.Response.WriteAsync("response"); } if (context.Request.Path.ToString() == "/test/error") { context.Response.StatusCode = 500; return context.Response.WriteAsync("response"); } if (context.Request.Path.ToString() == "/test/size") { return context.Response.WriteAsync("response"); } if (context.Request.Path.ToString() == "/test/post") { return context.Response.WriteAsync("response"); } context.Response.StatusCode = 404; return context.Response.WriteAsync("not found"); }); }); ExpectedResults = new OwinExpectedMetrics(timePerRequest, 6, 1); server.HttpClient.GetAsync("http://local.test/test/error").Result.StatusCode.Should().Be(HttpStatusCode.InternalServerError); server.HttpClient.GetAsync("http://local.test/test/action").Result.StatusCode.Should().Be(HttpStatusCode.OK); server.HttpClient.GetAsync("http://local.test/test/action").Result.StatusCode.Should().Be(HttpStatusCode.OK); server.HttpClient.GetAsync("http://local.test/test/action").Result.StatusCode.Should().Be(HttpStatusCode.OK); server.HttpClient.GetAsync("http://local.test/test/action").Result.StatusCode.Should().Be(HttpStatusCode.OK); var postContent = new StringContent(json); postContent.Headers.Add("Content-Length", json.Length.ToString()); server.HttpClient.PostAsync("http://local.test/test/post", postContent); }
private static void AppendHistogram(StringBuilder sb, HistogramMetric histogram) { sb.Append("{"); AppendDistribution(sb, histogram); sb.Append("}"); }
public void SampleMin_WhenThereAReNoValues_Returns0() { var underTest = new HistogramMetric(HistogramMetric.SampleType.Uniform); Assert.AreEqual(0, underTest.SampleMin); }
public CollectionDetails() { _stats = new HistogramMetric(HistogramMetric.SampleType.Uniform); _topDocs = new SortedList <int, string>(new IntDescComparer()); }
static void Main(string[] args) { var options = new Options(); if (!Parser.Default.ParseArguments(args, options, (t, o) => { target = t; targetOptions = o as CommonOptions; })) { Console.WriteLine(new CommonOptions().GetUsage()); Environment.Exit(CommandLine.Parser.DefaultExitCodeFail); } BenchmarkRunner.DefaultTotalSeconds = targetOptions.Seconds; BenchmarkRunner.DefaultMaxThreads = targetOptions.MaxThreads; //Metric.Config.WithHttpEndpoint("http://localhost:1234/"); switch (target) { case "noop": BenchmarkRunner.Run("Noop", () => { }); break; case "counter": var counter = new CounterMetric(); BenchmarkRunner.Run("Counter", () => counter.Increment()); break; case "meter": var meter = new MeterMetric(); BenchmarkRunner.Run("Meter", () => meter.Mark()); break; case "histogram": var histogram = new HistogramMetric(); BenchmarkRunner.Run("Histogram", () => histogram.Update(137)); break; case "timer": var timer = new TimerMetric(); BenchmarkRunner.Run("Timer", () => timer.Record(1, TimeUnit.Milliseconds)); break; case "hdrtimer": var hdrTimer = new TimerMetric(new HdrHistogramReservoir()); BenchmarkRunner.Run("HDR Timer", () => hdrTimer.Record(1, TimeUnit.Milliseconds)); break; case "ewma": var ewma = EWMA.OneMinuteEWMA(); BenchmarkRunner.Run("EWMA", () => ewma.Update(1)); break; case "edr": var edr = new ExponentiallyDecayingReservoir(); BenchmarkRunner.Run("EDR", () => edr.Update(1)); break; case "hdr": var hdrReservoir = new HdrHistogramReservoir(); BenchmarkRunner.Run("HDR Recorder", () => hdrReservoir.Update(1)); break; case "uniform": var uniform = new UniformReservoir(); BenchmarkRunner.Run("Uniform", () => uniform.Update(1)); break; case "sliding": var sliding = new SlidingWindowReservoir(); BenchmarkRunner.Run("Sliding", () => sliding.Update(1)); break; case "timerimpact": var load = new WorkLoad(); BenchmarkRunner.Run("WorkWithoutTimer", () => load.DoSomeWork(), iterationsChunk: 10); BenchmarkRunner.Run("WorkWithTimer", () => load.DoSomeWorkWithATimer(), iterationsChunk: 10); break; } }