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())); }
private void registerMetricsServlets(final ServletContextHandler context) { context.addEventListener(new ExampleHealthCheckServletContextListener()); context.addEventListener(new ExampleMetricsServletContextListener()); context.addServlet(AdminServlet.class, "/admin"); context.addServlet(HealthCheckServlet.class, "/admin/healthcheck"); context.addServlet(MetricsServlet.class, "/admin/metrics"); context.addServlet(PingServlet.class, "/admin/ping"); context.addServlet(ThreadDumpServlet.class, "/admin/threads"); }
@Override protected void configure() { // NOTE: AdminServletModule (metrics-guice integration) generates invalid links, so wire up servlets ourselves final Clock clock = Clock.defaultClock(); bind(Clock.class).toInstance(clock); final JsonFactory jsonFactory = new JsonFactory(new ObjectMapper()); bind(JsonFactory.class).toInstance(jsonFactory); install(new ServletModule() { @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); } }); // require permission to use endpoints install(new FilterChainModule() { @Override protected void configure() { addFilterChain(MOUNT_POINT + "/**", NexusAuthenticationFilter.NAME, AnonymousFilter.NAME, PermissionsFilter.config("nexus:metrics:read")); } }); log.info("Metrics support configured"); }