示例#1
0
        public void FlotVisualization_CanReadAppFromResource()
        {
            var html = FlotWebApp.GetFlotApp();

            html.Should().NotBeEmpty();
            Assert.DoesNotThrow(() => CQ.CreateDocument(html));
        }
示例#2
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();
        }
示例#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);
        }
        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));
        }
示例#5
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();
 }