private ServletContextHandler getMetricsHandler() { MetricRegistry registry = Metrics.getRegistry(); HealthCheckRegistry healthCheckRegistry = Metrics.getHealthCheckRegistry(); healthCheckRegistry.register("rotation", new Rotation(configuration.getRotationStatusFilePath())); registry.registerAll(new GarbageCollectorMetricSet()); registry.registerAll(new MemoryUsageGaugeSet()); registry.registerAll(new ThreadStatesGaugeSet()); registry.registerAll(new JvmAttributeGaugeSet()); ServletContextHandler servletContextHandler = new ServletContextHandler(); servletContextHandler.setContextPath("/__metrics"); servletContextHandler.setAttribute(MetricsServlet.class.getCanonicalName() + ".registry", registry); servletContextHandler.setAttribute(HealthCheckServlet.class.getCanonicalName() + ".registry", healthCheckRegistry); servletContextHandler.addServlet(new ServletHolder(new AdminServlet()), "/*"); return servletContextHandler; }
@Bean @Autowired public ServletRegistrationBean servletHealthRegistryBean(HealthCheckRegistry healthCheckRegistry) { HealthCheckServlet hc = new HealthCheckServlet(healthCheckRegistry); ServletRegistrationBean srb = new ServletRegistrationBean(hc, "/health/*"); srb.setLoadOnStartup(2); return srb; }
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { servletContextEvent.getServletContext().setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, healthCheckRegistry); servletContextEvent.getServletContext().setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry); // metricRegistry.counter("teste"); }
@Override public void setServletContext(final ServletContext servletContext) { servletContext.setAttribute(MetricsServlet.METRICS_REGISTRY, this.metricsRegistry); servletContext.setAttribute(MetricsServlet.SHOW_SAMPLES, Boolean.TRUE); servletContext.setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, this.healthCheckRegistry); }
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"); }
@Bean(initMethod="start", destroyMethod="stop") @Order(0) public Server adminServer( @Value("${admin.hostname}") String hostname, @Value("${admin.port}") int port) { // set up servlets ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY); context.setErrorHandler(null); context.setWelcomeFiles(new String[] { "/" }); // enable gzip context.addFilter(GzipFilter.class, "/*", null); // add common admin servlets context.addServlet(new ServletHolder(new HealthServlet(healthCheckRegistry)), "/healthcheck"); context.addServlet(new ServletHolder(new ClasspathResourceServlet("com/kixeye/chassis/transport/admin", "/admin/", "index.html")), "/admin/*"); context.addServlet(new ServletHolder(new PropertiesServlet()), "/admin/properties"); context.addServlet(new ServletHolder(new ClasspathDumpServlet()), "/admin/classpath"); // add websocket servlets if WebSockets have been initialized if (mappingRegistry != null && messageRegistry != null) { context.addServlet(new ServletHolder(new ProtobufMessagesDocumentationServlet(appName, mappingRegistry, messageRegistry)), "/schema/messages/protobuf"); context.addServlet(new ServletHolder(new ProtobufEnvelopeDocumentationServlet()), "/schema/envelope/protobuf"); } // add metric servlets if Metric has been initialized if (metricRegistry != null && healthCheckRegistry != null) { context.getServletContext().setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry); context.getServletContext().setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, healthCheckRegistry); ServletHolder holder = new ServletHolder(new AdminServlet()); holder.setInitParameter("service-name", System.getProperty("app.name")); context.addServlet(holder, "/metrics/*"); } // create the server InetSocketAddress address = StringUtils.isBlank(hostname) ? new InetSocketAddress(port) : new InetSocketAddress(hostname, port); Server server = new Server(); JettyConnectorRegistry.registerHttpConnector(server, address); server.setHandler(context); return server; }
public StartReportingMetricsToHTTP(CommandBuilder builder, Config config, Command parent, Command child, final MorphlineContext context) { super(builder, config, parent, child, context); this.port = getConfigs().getInt(config, "port", 8080); final TimeUnit defaultDurationUnit = getConfigs().getTimeUnit(config, "defaultDurationUnit", TimeUnit.MILLISECONDS); final TimeUnit defaultRateUnit = getConfigs().getTimeUnit(config, "defaultRateUnit", TimeUnit.SECONDS); validateArguments(); synchronized (SERVERS) { Server server = SERVERS.get(port); if (server == null) { ServletContextHandler servletContextHandler = new ServletContextHandler(); servletContextHandler.addServlet(AdminServlet.class, "/*"); servletContextHandler.addEventListener(new MetricsServlet.ContextListener() { @Override protected MetricRegistry getMetricRegistry() { return context.getMetricRegistry(); } @Override protected TimeUnit getRateUnit() { return defaultRateUnit; } @Override protected TimeUnit getDurationUnit() { return defaultDurationUnit; } }); servletContextHandler.addEventListener(new HealthCheckServlet.ContextListener() { @Override protected HealthCheckRegistry getHealthCheckRegistry() { return context.getHealthCheckRegistry(); } }); server = new Server(port); server.setHandler(servletContextHandler); try { server.start(); } catch (Exception e) { throw new MorphlineRuntimeException(e); } SERVERS.put(port, server); } } }
public InternalContext(HealthCheckRegistry healthCheckRegistry, MetricRegistry metricRegistry) { super(); getServletContext().setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, healthCheckRegistry); getServletContext().setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry); }