/** * Method: init * Purpose: Initializes the embedded Jetty Server with including the metrics servlets. */ private void init() { LOG.info("Initializing Kafka Http Metrics Reporter"); // creating the socket address for binding to the specified address and port InetSocketAddress inetSocketAddress = new InetSocketAddress(bindAddress, port); // create new Jetty server server = new Server(inetSocketAddress); // creating the servlet context handler ServletContextHandler servletContextHandler = new ServletContextHandler(); // setting the context path servletContextHandler.setContextPath("/"); // adding the codahale metrics servlet to the servlet context servletContextHandler.addServlet(new ServletHolder(new AdminServlet()), "/api"); servletContextHandler.addServlet(new ServletHolder(new MetricsServlet()), "/api/metrics"); servletContextHandler.addServlet(new ServletHolder(new ThreadDumpServlet()), "/api/threads"); servletContextHandler.addServlet(new ServletHolder(new HealthCheckServlet()), "/api/healthcheck"); servletContextHandler.addServlet(new ServletHolder(new PingServlet()), "/api/ping"); // adding the configured servlet context handler to the Jetty Server server.setHandler(servletContextHandler); LOG.info("Finished initializing Kafka Http Metrics Reporter"); }
public AdminServlet(HealthCheckServlet healthCheckServlet, MetricsServlet metricsServlet, PingServlet pingServlet, ThreadDumpServlet threadDumpServlet, String healthcheckUri, String metricsUri, String pingUri, String threadsUri) { this.healthCheckServlet = healthCheckServlet; this.metricsServlet = metricsServlet; this.pingServlet = pingServlet; this.threadDumpServlet = threadDumpServlet; this.metricsUri = metricsUri; this.pingUri = pingUri; this.threadsUri = threadsUri; this.healthcheckUri = healthcheckUri; }
@Override public AdminServlet get() { for (HealthCheck healthCheck : healthChecks) { healthCheckRegistry.register(healthCheck); } final JsonFactory factory = jsonFactory == null ? new JsonFactory(new ObjectMapper()) : jsonFactory; return new AdminServlet(new HealthCheckServlet(healthCheckRegistry), new MetricsServlet(Clock.defaultClock(), VirtualMachineMetrics.getInstance(), metricsRegistry, factory, true), new PingServlet(), new ThreadDumpServlet(VirtualMachineMetrics.getInstance()), healthcheckUri, metricsUri, pingUri, threadsUri); } }