Class HTTPServer

java.lang.Object
io.prometheus.client.exporter.HTTPServer

public class HTTPServer extends Object
Expose Prometheus metrics using a plain Java HttpServer.

Example Usage:

 
 HTTPServer server = new HTTPServer(1234);
 
 
  • Field Details

    • server

      protected final com.sun.net.httpserver.HttpServer server
    • executorService

      protected final ExecutorService executorService
  • Constructor Details

    • HTTPServer

      public HTTPServer(com.sun.net.httpserver.HttpServer httpServer, CollectorRegistry registry, boolean daemon) throws IOException
      Start a HTTP server serving Prometheus metrics from the given registry using the given HttpServer. The httpServer is expected to already be bound to an address
      Throws:
      IOException
    • HTTPServer

      public HTTPServer(InetSocketAddress addr, CollectorRegistry registry, boolean daemon) throws IOException
      Start a HTTP server serving Prometheus metrics from the given registry.
      Throws:
      IOException
    • HTTPServer

      public HTTPServer(InetSocketAddress addr, CollectorRegistry registry) throws IOException
      Start a HTTP server serving Prometheus metrics from the given registry using non-daemon threads.
      Throws:
      IOException
    • HTTPServer

      public HTTPServer(int port, boolean daemon) throws IOException
      Start a HTTP server serving the default Prometheus registry.
      Throws:
      IOException
    • HTTPServer

      public HTTPServer(int port) throws IOException
      Start a HTTP server serving the default Prometheus registry using non-daemon threads.
      Throws:
      IOException
    • HTTPServer

      public HTTPServer(String host, int port, boolean daemon) throws IOException
      Start a HTTP server serving the default Prometheus registry.
      Throws:
      IOException
    • HTTPServer

      public HTTPServer(String host, int port) throws IOException
      Start a HTTP server serving the default Prometheus registry using non-daemon threads.
      Throws:
      IOException
  • Method Details

    • shouldUseCompression

      protected static boolean shouldUseCompression(com.sun.net.httpserver.HttpExchange exchange)
    • parseQuery

      protected static Set<String> parseQuery(String query) throws IOException
      Throws:
      IOException
    • start

      private void start(boolean daemon)
      Start a HTTP server by making sure that its background thread inherit proper daemon flag.
    • stop

      public void stop()
      Stop the HTTP server.
    • getPort

      public int getPort()
      Gets the port number.