예제 #1
0
        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();
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }