Search in sources :

Example 1 with MetricsServlet

use of io.prometheus.client.exporter.MetricsServlet in project incubator-pulsar by apache.

the class ZooKeeperStarter method start.

protected static void start(String[] args, String defaultStatsPort) throws Exception {
    // Register basic JVM metrics
    DefaultExports.initialize();
    // load aspectj-weaver agent for instrumentation
    AgentLoader.loadAgentClass(Agent.class.getName(), null);
    // Start Jetty to serve stats
    int port = Integer.parseInt(System.getProperties().getProperty("stats_server_port", defaultStatsPort));
    log.info("Starting ZK stats HTTP server at port {}", port);
    InetSocketAddress httpEndpoint = InetSocketAddress.createUnresolved("0.0.0.0", port);
    Server server = new Server(httpEndpoint);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
    try {
        server.start();
    } catch (Exception e) {
        log.error("Failed to start HTTP server at port {}. Use \"-Dstats_server_port=1234\" to change port number", port, e);
        throw e;
    }
    // Start the regular ZooKeeper server
    QuorumPeerMain.main(args);
}
Also used : Agent(org.aspectj.weaver.loadtime.Agent) Server(org.eclipse.jetty.server.Server) MetricsServlet(io.prometheus.client.exporter.MetricsServlet) InetSocketAddress(java.net.InetSocketAddress) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 2 with MetricsServlet

use of io.prometheus.client.exporter.MetricsServlet in project infrautils by opendaylight.

the class OsgiWebInitializer method init.

@PostConstruct
public void init() throws ServletException, NamespaceException {
    MetricsServlet metricsServlet = new MetricsServlet(collectorRegistry);
    osgiHttpService.registerServlet(PROMETHEUS_METRICS_URL, metricsServlet, null, null);
    LOG.info("Metrics for Prometheus scrape now exposed on: {}", PROMETHEUS_METRICS_URL);
}
Also used : MetricsServlet(io.prometheus.client.exporter.MetricsServlet) PostConstruct(javax.annotation.PostConstruct)

Aggregations

MetricsServlet (io.prometheus.client.exporter.MetricsServlet)2 InetSocketAddress (java.net.InetSocketAddress)1 PostConstruct (javax.annotation.PostConstruct)1 Agent (org.aspectj.weaver.loadtime.Agent)1 Server (org.eclipse.jetty.server.Server)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1