public MetricsModule() : base(Config.ModulePath ?? "/") { if (string.IsNullOrEmpty(Config.ModulePath)) { return; } if (Config.ModuleConfigAction != null) { Config.ModuleConfigAction(this); } 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(GetAsHumanReadable()); Get["/json"] = _ => Response.AsText(RegistrySerializer.GetAsJson(Config.Registry), "text/json"); Get["/ping"] = _ => Response.AsText("pong", "text/plain"); Get["/health"] = _ => GetHealthStatus(); }
private static void WriteJsonMetrics(HttpListenerContext context, MetricsRegistry registry) { context.Response.Headers.Add("Access-Control-Allow-Origin", "*"); context.Response.Headers.Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); context.Response.ContentType = "application/json"; context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; var json = RegistrySerializer.GetAsJson(registry); using (var writer = new StreamWriter(context.Response.OutputStream)) { writer.Write(json); } context.Response.Close(); }