public void startServer() throws Exception { if (this.bindAddress != null) { this.server = new Server(new InetSocketAddress(InetAddress.getByName(this.bindAddress), port)); } else { this.server = new Server(this.port); } ServletContextHandler handler = new ServletContextHandler(this.server, pathPrefix); if (metricsRegistries != null) { // TODO: there is a way to wire these up automagically via the AdminServlet, but it escapes me right now handler.addServlet(new ServletHolder(new MetricsServlet(metricsRegistries.metricRegistry)), "/metrics"); handler.addServlet(new ServletHolder(new io.prometheus.client.exporter.MetricsServlet()), "/prometheus"); handler.addServlet(new ServletHolder(new HealthCheckServlet(metricsRegistries.healthCheckRegistry)), "/healthcheck"); handler.addServlet(new ServletHolder(new PingServlet()), "/ping"); } if (diagnosticContext != null) { handler.addServlet(new ServletHolder(new DiagnosticHealthCheck(diagnosticContext)), "/diagnostic"); } this.server.start(); this.server.join(); }
@Override public void init(ServletConfig config) throws ServletException { super.init(config); this.healthCheckServlet = new HealthCheckServlet(); healthCheckServlet.init(config); this.metricsServlet = new MetricsServlet(); metricsServlet.init(config); this.pingServlet = new PingServlet(); pingServlet.init(config); this.threadDumpServlet = new ThreadDumpServlet(); threadDumpServlet.init(config); this.metricsUri = getParam(config.getInitParameter("metrics-uri"), DEFAULT_METRICS_URI); this.pingUri = getParam(config.getInitParameter("ping-uri"), DEFAULT_PING_URI); this.threadsUri = getParam(config.getInitParameter("threads-uri"), DEFAULT_THREADS_URI); this.healthcheckUri = getParam(config.getInitParameter("healthcheck-uri"), DEFAULT_HEALTHCHECK_URI); this.serviceName = getParam(config.getInitParameter("service-name"), null); }
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final String uri = req.getPathInfo(); if (uri == null || uri.equals("/")) { super.service(req, resp); } else if (uri.equals(healthcheckUri)) { healthCheckServlet.service(req, resp); } else if (uri.startsWith(metricsUri)) { metricsServlet.service(req, resp); } else if (uri.equals(pingUri)) { pingServlet.service(req, resp); } else if (uri.equals(threadsUri)) { threadDumpServlet.service(req, resp); } else { resp.sendError(HttpServletResponse.SC_NOT_FOUND); } }
@Activate protected void activate() throws NamespaceException, ServletException { httpService.registerServlet(METRICS_URI, new MetricsServlet(metricRegistry), null, null); httpService.registerServlet(HEALTH_URI, new HealthCheckServlet(healthCheckRegistry), null, null); httpService.registerServlet(PING_URI, new PingServlet(), null, null); httpService.registerServlet(THREADS_URI, new ThreadDumpServlet(), null, null); }
serve(SYSTEM_HEALTHCHECK).with(new HealthCheckServlet(monitoring.getHealth())); serve(SYSTEM_METRICS).with(new MetricsServlet(monitoring.getMetrics())); serve(SYSTEM_PING).with(new PingServlet()); serve(SYSTEM_THREADS).with(new ThreadDumpServlet());
private void evaluateWeb() throws Exception { if (!runPerServiceMode(web)) { return; } // Load balancers should hit the ping servlet, exposed on the main port to reflect main connection pool issues _environment.servlets().addServlet("/ping", new PingServlet()); // Serve static assets _environment.jersey().register(FaviconResource.class); // Add a filter to provide finer 5xx metrics than the default DropWizard metrics include. //noinspection unchecked _environment.jersey().getResourceConfig().getContainerResponseFilters() .add(new ServerErrorResponseMetricsFilter(_environment.metrics())); }
serve(SYSTEM_HEALTHCHECK).with(new HealthCheckServlet(monitoring.getHealth())); serve(SYSTEM_METRICS).with(new MetricsServlet(monitoring.getMetrics())); serve(SYSTEM_PING).with(new PingServlet()); serve(SYSTEM_THREADS).with(new ThreadDumpServlet());
@Override protected void configureServlets() { bind(MetricsServlet.class); bind(HealthCheckServlet.class); serve(MOUNT_POINT + "/ping").with(new PingServlet()); serve(MOUNT_POINT + "/threads").with(new ThreadDumpServlet()); serve(MOUNT_POINT + "/data").with(MetricsServlet.class); serve(MOUNT_POINT + "/healthcheck").with(HealthCheckServlet.class); // record metrics for all webapp access filter("/*").through(new InstrumentedFilter()); bind(SecurityFilter.class); // configure security filter(MOUNT_POINT + "/*").through(SecurityFilter.class); } });