com.codahale.metrics.servlets.PingServlet Java Examples

The following examples show how to use com.codahale.metrics.servlets.PingServlet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpMetricsServer.java    From hermes with Apache License 2.0 6 votes vote down vote up
private void init() {
	logger.info("Initializing Broker Http Metrics Reporter");

	InetSocketAddress inetSocketAddress = new InetSocketAddress(bindAddress, port);

	server = new Server(inetSocketAddress);

	ServletContextHandler servletContextHandler = new ServletContextHandler();

	servletContextHandler.setContextPath("/");

	servletContextHandler.addEventListener(new MetricsServletContextListener());
	servletContextHandler.addEventListener(new JVMMetricsServletContextListener());
	servletContextHandler.addEventListener(new HealthCheckServletContextListener());

	servletContextHandler.addServlet(new ServletHolder(new HermesServlet()), "/hermes");
	servletContextHandler.addServlet(new ServletHolder(new MetricsServlet()), "/metrics/metrics");
	servletContextHandler.addServlet(new ServletHolder(new ThreadDumpServlet()), "/metrics/threads");
	servletContextHandler.addServlet(new ServletHolder(new HealthCheckServlet()), "/metrics/healthcheck");
	servletContextHandler.addServlet(new ServletHolder(new PingServlet()), "/metrics/ping");

	server.setHandler(servletContextHandler);
	logger.info("Finished initializing Broker Http Metrics Reporter");
}
 
Example #2
Source File: EmoService.java    From emodb with Apache License 2.0 6 votes vote down vote up
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()));
}
 
Example #3
Source File: CassandraConnectorTask.java    From debezium-incubator with Apache License 2.0 5 votes vote down vote up
private void initHttpServer() {
    int httpPort = config.httpPort();
    LOGGER.info("HTTP port is {}", httpPort);
    httpServer = new Server(httpPort);

    ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    contextHandler.setContextPath("/");
    httpServer.setHandler(contextHandler);

    contextHandler.addServlet(new ServletHolder(new PingServlet()), "/ping");
    contextHandler.addServlet(new ServletHolder(new BuildInfoServlet(getBuildInfoMap(this.getClass()))), "/buildinfo");
    contextHandler.addServlet(new ServletHolder(new MetricsServlet(METRIC_REGISTRY_INSTANCE)), "/metrics");
    contextHandler.addServlet(new ServletHolder(new HealthCheckServlet(registerHealthCheck())), "/health");
}
 
Example #4
Source File: HermesServlet.java    From hermes with Apache License 2.0 5 votes vote down vote up
public void init(ServletConfig config) throws ServletException {
	this.config = config;
	if (Boolean.valueOf(config.getInitParameter("show-jvm-metrics"))) {
		JVMMetricsServletContextListener listener = new JVMMetricsServletContextListener();
		this.jvmServlet = new JVMMetricsServlet(listener.getMetricRegistry());
		this.jvmServlet.init(config);

		this.jvmUri = "/jvm";
	}

	healthCheckServlet = new HealthCheckServlet(HermesMetricsRegistry.getHealthCheckRegistry());
	healthCheckServlet.init(config);

	pingServlet = new PingServlet();
	pingServlet.init(config);

	threadDumpServlet = new ThreadDumpServlet();
	threadDumpServlet.init(config);

	metricServlet = new MetricsServlet(HermesMetricsRegistry.getMetricRegistry());
	metricServlet.init(config);

	this.metricServletGroupByT = new HashMap<String, MetricsServlet>();
	this.metricServletGroupByTP = new HashMap<String, MetricsServlet>();
	this.metricServletGroupByTPG = new HashMap<String, MetricsServlet>();

	this.healthcheckUri = "/healthcheck";
	this.pingUri = "/ping";
	this.threadsUri = "/threads";
	this.globalUri = "/global";
	this.metricsUri = "/metrics";
}
 
Example #5
Source File: MetricsModule.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@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);
      serve(MOUNT_POINT + "/prometheus").with(new io.prometheus.client.exporter.MetricsServlet());

      // 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,
          AntiCsrfFilter.NAME,
          PermissionsFilter.config("nexus:metrics:read"));
    }
  });

  log.info("Metrics support configured");
}