public void can_report_health_checks() { var expected = StringReporterSamples.HealthChecks.ExtractStringReporterSampleFromResourceFile(); var globalTags = new GlobalMetricTags(new Dictionary <string, string> { { "tag_key", "tag_value" } }); var healthyChecks = new[] { new HealthCheck.Result("healthy check", HealthCheckResult.Healthy("healthy message")) }.AsEnumerable(); var degradedChecks = new[] { new HealthCheck.Result("degraded check", HealthCheckResult.Degraded("degraded message")) }.AsEnumerable(); var unhealthyChecks = new[] { new HealthCheck.Result("unhealthy check", HealthCheckResult.Unhealthy("unhealthy message")) }.AsEnumerable(); var sr = new StringReporter(); sr.ReportHealth(globalTags, healthyChecks, degradedChecks, unhealthyChecks); AssertReportResult(sr.Result, expected); }
private static string GetAsHumanReadable() { var report = new StringReporter(); report.RunReport(Config.Registry, Config.HealthStatus); return(report.Result); }
public void can_report_counters() { var expected = StringReporterSamples.Counters.ExtractStringReporterSampleFromResourceFile(); var sr = new StringReporter(); sr.ReportMetric("test", new CounterValueSource("counter_name", new CounterMetric(), Unit.None, MetricTags.None)); AssertReportResult(sr.Result, expected); }
public void can_report_gauges() { var expected = StringReporterSamples.Gauges.ExtractStringReporterSampleFromResourceFile(); var sr = new StringReporter(); sr.ReportMetric("test", new GaugeValueSource("gauge_name", new FunctionGauge(() => 2), Unit.None, MetricTags.None)); AssertReportResult(sr.Result, expected); }
public MetricsEndpointTextEndpointMiddleware(RequestDelegate next, AspNetMetricsOptions aspNetOptions, ILoggerFactory loggerFactory, IMetrics metrics) : base(next, aspNetOptions, loggerFactory, metrics) { _stringReporter = new StringReporter(); _reportGenerator = new DefaultReportGenerator(); }
public void reporter_name_is_required() { Action action = () => { var sr = new StringReporter(null); }; action.ShouldThrow <ArgumentNullException>(); }
public void when_disposed_buffer_is_cleared() { var envInfo = new EnvironmentInfo("assembly", "entry", "host", "time", "machine", "OS", "OS version", "process", "4"); var sr = new StringReporter(); sr.ReportEnvironment(envInfo); sr.Dispose(); sr.Result.IsNullOrEmpty(); }
public void can_report_environment_info() { var expected = StringReporterSamples.EnvironmentInfo.ExtractStringReporterSampleFromResourceFile(); var envInfo = new EnvironmentInfo("assembly", "entry", "host", "time", "machine", "OS", "OS version", "process", "4"); var sr = new StringReporter(); sr.ReportEnvironment(envInfo); AssertReportResult(sr.Result, expected); }
public TextFileReporter(string name, string file, TimeSpan interval) { if (file == null) { throw new ArgumentNullException(nameof(file)); } _file = file; _stringReporter = new StringReporter(name); ReportInterval = interval; }
public void can_report_meters() { var expected = StringReporterSamples.Meters.ExtractStringReporterSampleFromResourceFile(); var clock = new TestClock(); var sr = new StringReporter(); var metric = new MeterMetric(clock, new TestTaskScheduler(clock)); metric.Mark(1); sr.ReportMetric("test", new MeterValueSource("meter_name", metric, Unit.None, TimeUnit.Milliseconds, MetricTags.None)); AssertReportResult(sr.Result, expected); }
public void can_report_histograms() { var expected = StringReporterSamples.Histograms.ExtractStringReporterSampleFromResourceFile(); var sr = new StringReporter(); var metric = new DefaultHistogramMetric(_defaultReservoir); metric.Update(1000, "value1"); metric.Update(2000, "value2"); sr.ReportMetric("test", new HistogramValueSource("histogram_name", metric, Unit.None, MetricTags.None)); AssertReportResult(sr.Result, expected); }
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 WriteTextMetrics(HttpListenerContext context, MetricsDataProvider metricsDataProvider, Func <HealthStatus> healthStatus) { context.Response.ContentType = "text/plain"; context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; AddNoCacheHeaders(context.Response); using (var writer = new StreamWriter(context.Response.OutputStream)) { writer.Write(StringReporter.RenderMetrics(metricsDataProvider.CurrentMetricsData, healthStatus)); } context.Response.Close(); }
public void can_report_apdex() { var expected = StringReporterSamples.Apdex.ExtractStringReporterSampleFromResourceFile(); var clock = new TestClock(); var sr = new StringReporter(); var reservoir = new ExponentiallyDecayingReservoir(Constants.ReservoirSampling.DefaultSampleSize, Constants.ReservoirSampling.DefaultExponentialDecayFactor, clock, new TestTaskScheduler(clock)); var metric = new ApdexMetric(new ApdexProvider(reservoir, Constants.ReservoirSampling.DefaultApdexTSeconds), clock, true); metric.Track(1000); sr.ReportMetric("test", new ApdexValueSource("apdex_name", metric, MetricTags.None)); AssertReportResult(sr.Result, expected); }
public TextFileReporter(string name, string file, TimeSpan interval, ILoggerFactory loggerFactory) { if (file == null) { throw new ArgumentNullException(nameof(file)); } if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } _file = file; _logger = loggerFactory.CreateLogger <TextFileReporter>(); _stringReporter = new StringReporter(name); ReportInterval = interval; }
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); }
public MetricsModule() : base(Config.ModulePath ?? "/") { if (string.IsNullOrEmpty(Config.ModulePath)) { return; } if (Config.ModuleConfigAction != null) { Config.ModuleConfigAction(this); } var noCacheHeaders = new[] { new { Header = "Cache-Control", Value = "no-cache, no-store, must-revalidate" }, new { Header = "Pragma", Value = "no-cache" }, new { Header = "Expires", Value = "0" } }; Get["/"] = _ => { if (this.Request.Url.Path.EndsWith("/")) { return(Response.AsText(FlotWebApp.GetFlotApp(), "text/html")); } else { return(Response.AsRedirect(this.Request.Url.ToString() + "/")); } }; Get["/text"] = _ => Response.AsText(StringReporter.RenderMetrics(Config.MetricsContext.DataProvider.CurrentMetricsData, Config.HealthStatus)) .WithHeaders(noCacheHeaders); Get["/json"] = _ => Response.AsText(OldJsonBuilder.BuildJson(Config.MetricsContext.DataProvider.CurrentMetricsData, Clock.Default), "text/json") .WithHeaders(noCacheHeaders); Get["/jsonnew"] = _ => Response.AsText(JsonMetrics.Serialize(Config.MetricsContext.DataProvider.CurrentMetricsData), "text/json") .WithHeaders(noCacheHeaders); Get["/ping"] = _ => Response.AsText("pong", "text/plain") .WithHeaders(noCacheHeaders); Get["/health"] = _ => GetHealthStatus() .WithHeaders(noCacheHeaders); }
public async Task Invoke(HttpContext context) { if (Options.MetricsTextEndpointEnabled && Options.MetricsTextEndpoint.IsPresent() && Options.MetricsTextEndpoint == context.Request.Path) { Logger.MiddlewareExecuting(GetType()); var stringReporter = new StringReporter(); await _reportGenerator.GenerateAsync(stringReporter, Metrics, context.RequestAborted); await WriteResponseAsync(context, stringReporter.Result, "text/plain"); Logger.MiddlewareExecuted(GetType()); return; } await Next(context); }
public async Task Invoke(IDictionary <string, object> environment) { var requestPath = environment["owin.RequestPath"] as string; if (Options.MetricsTextEndpointEnabled && Options.MetricsTextEndpoint.IsPresent() && Options.MetricsTextEndpoint == requestPath) { Logger.MiddlewareExecuting(GetType()); var stringReporter = new StringReporter(); //TODO: AH - confirm cancellation token is correct var cancellationToken = (CancellationToken)environment["owin.CallCancelled"]; await _reportGenerator.GenerateAsync(stringReporter, Metrics, cancellationToken); await WriteResponseAsync(environment, stringReporter.Result, "text/plain"); Logger.MiddlewareExecuted(GetType()); return; } await Next(environment); }
public void can_report_timers() { var expected = StringReporterSamples.Timers.ExtractStringReporterSampleFromResourceFile(); var sr = new StringReporter(); var clock = new TestClock(); var histogram = new DefaultHistogramMetric(_defaultReservoir); var metric = new DefaultTimerMetric(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 static Task GetAsHumanReadable(IDictionary <string, object> environment, MetricsData metricsData, Func <HealthStatus> healthStatus) { string text = StringReporter.RenderMetrics(metricsData, healthStatus); return(WriteResponse(environment, text, "text/plain")); }
/// <summary> /// Initializes a new instance of the <see cref="TextFileReporter"/> class. /// </summary> public TextFileReporter() { this.decoratedReporter = new StringReporter(); }
/// <summary> /// Initializes a new instance of the <see cref="TextFileReporter"/> class. /// </summary> public TextFileReporter() { this.decoratedReporter = new StringReporter(); }
private static Task WriteTextMetrics(HttpListenerContext context, MetricsDataProvider metricsDataProvider, Func <HealthStatus> healthStatus) { var text = StringReporter.RenderMetrics(metricsDataProvider.CurrentMetricsData, healthStatus); return(WriteString(context, text, "text/plain")); }