private static Task WriteJsonMetricsV1(HttpListenerContext context, MetricsDataProvider metricsDataProvider) { var json = JsonBuilderV1.BuildJson(metricsDataProvider.CurrentMetricsData); jsonSize.Update(json.Length / 1024); return(WriteString(context, json, JsonBuilderV1.MetricsMimeType)); }
private static void WriteJsonMetricsV1(HttpListenerContext context, MetricsDataProvider metricsDataProvider) { using (jsonv1Metrics.NewContext()) { var json = JsonBuilderV1.BuildJson(metricsDataProvider.CurrentMetricsData); jsonv1Size.Update(json.Length / 1024); WriteString(context, json, JsonBuilderV1.MetricsMimeType); } }
public MetricsModule() : base(Config.ModulePath ?? "/") { if (string.IsNullOrEmpty(Config.ModulePath)) { return; } if (Config.ModuleConfigAction != null) { Config.ModuleConfigAction(this); } object[] noCacheHeaders = { 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.AsRedirect(this.Request.Url.ToString() + "/")); } var gzip = AcceptsGzip(); var response = Response.FromStream(FlotWebApp.GetAppStream(!gzip), "text/html"); if (gzip) { response.WithHeader("Content-Encoding", "gzip"); } return(response); }; Get["/text"] = _ => Response.AsText(StringReport.RenderMetrics(Config.DataProvider.CurrentMetricsData, Config.HealthStatus)) .WithHeaders(noCacheHeaders); Get["/json"] = _ => Response.AsText(JsonBuilderV1.BuildJson(Config.DataProvider.CurrentMetricsData), "text/json") .WithHeaders(noCacheHeaders); Get["/v2/json"] = _ => Response.AsText(JsonBuilderV2.BuildJson(Config.DataProvider.CurrentMetricsData), "text/json") .WithHeaders(noCacheHeaders); Get["/ping"] = _ => Response.AsText("pong", "text/plain") .WithHeaders(noCacheHeaders); Get["/health"] = _ => GetHealthStatus() .WithHeaders(noCacheHeaders); }
private static Task GetJsonContent(IDictionary <string, object> environment, MetricsDataProvider dataProvider) { var content = JsonBuilderV1.BuildJson(dataProvider.CurrentMetricsData, Clock.Default); return(WriteResponse(environment, content, "application/json")); }
private static MetricsEndpointResponse GetJsonV1Response(MetricsData data, Func <HealthStatus> healthStatus, MetricsEndpointRequest request) { var json = JsonBuilderV1.BuildJson(data); return(new MetricsEndpointResponse(json, JsonBuilderV1.MetricsMimeType)); }