Ejemplo n.º 1
0
        public MetricsModule()
            : base(MetricsModule.Config.ModulePath ?? "/")
        {
            if (string.IsNullOrEmpty(MetricsModule.Config.ModulePath))
            {
                return;
            }

            MetricsModule.Config.ModuleConfigAction?.Invoke(this);

            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);
            });

            // Greedy Segment - /{name*} by adding a star/asterisk to the end of the segment name,
            // the pattern will match any value from the current forward slash onward.
            Get("/{path*}", p =>
            {
                var path             = (string)p.path;
                var endpointResponse = MetricsModule.Config.Handler.Process(path, this.Request);
                return(endpointResponse != null ? GetResponse(endpointResponse) : HttpStatusCode.NotFound);
            });
        }
Ejemplo n.º 2
0
        public MetricsModule()
            : base(Config.ModulePath ?? "/")
        {
            if (string.IsNullOrEmpty(Config.ModulePath))
            {
                return;
            }

            Config.ModuleConfigAction?.Invoke(this);

            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["/{path*}"] = p =>
            {
                var path             = (string)p.path;
                var endpointResponse = Config.Handler.Process(path, this.Request);
                return(endpointResponse != null?GetResponse(endpointResponse) : HttpStatusCode.NotFound);
            };
        }
Ejemplo n.º 3
0
        public void FlotVisualization_CanReadAppFromResource()
        {
            var html = FlotWebApp.GetFlotApp();

            html.Should().NotBeEmpty();
            Assert.DoesNotThrow(() => CQ.CreateDocument(html));
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
        public Task Invoke(HttpContext context)
        {
            if (_options.MetricsEndpoint != "/json" && _options.MetricsVisualisationEnabled)
            {
                throw new NotImplementedException(
                          "metrics visualisation currently requires the metrics endpoint to be configured as /json. Disable metrics visualisation or change the metrics endpoint path.");
            }

            if (_options.HealthEndpoint != "/health" && _options.MetricsVisualisationEnabled)
            {
                throw new NotImplementedException(
                          "metrics visualisation currently requires the health endpoint to be configured as /health. Disable metrics visualisation or change the health check endpoint path.");
            }

            if (_options.MetricsVisualisationEnabled && _options.MetricsVisualizationEndpoint.HasValue &&
                _options.MetricsVisualizationEndpoint == context.Request.Path)
            {
                var content = FlotWebApp.GetFlotApp();
                return(WriteResponse(context, content, "text/html"));
            }

            return(_next(context));
        }
Ejemplo n.º 8
0
        private static Task GetFlotWebApp(IDictionary <string, object> environment)
        {
            var content = FlotWebApp.GetFlotApp();

            return(WriteResponse(environment, content, "text/html"));
        }
 public void CanReadAppFromResource()
 {
     FlotWebApp.GetFlotApp().Should().NotBeEmpty();
 }