Package io.prometheus.client.exporter
Class HTTPServer
java.lang.Object
io.prometheus.client.exporter.HTTPServer
Expose Prometheus metrics using a plain Java HttpServer.
Example Usage:
HTTPServer server = new HTTPServer(1234);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
private static class
(package private) static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ExecutorService
protected final com.sun.net.httpserver.HttpServer
-
Constructor Summary
ConstructorsConstructorDescriptionHTTPServer
(int port) Start a HTTP server serving the default Prometheus registry using non-daemon threads.HTTPServer
(int port, boolean daemon) Start a HTTP server serving the default Prometheus registry.HTTPServer
(com.sun.net.httpserver.HttpServer httpServer, CollectorRegistry registry, boolean daemon) Start a HTTP server serving Prometheus metrics from the given registry using the givenHttpServer
.HTTPServer
(String host, int port) Start a HTTP server serving the default Prometheus registry using non-daemon threads.HTTPServer
(String host, int port, boolean daemon) Start a HTTP server serving the default Prometheus registry.HTTPServer
(InetSocketAddress addr, CollectorRegistry registry) Start a HTTP server serving Prometheus metrics from the given registry using non-daemon threads.HTTPServer
(InetSocketAddress addr, CollectorRegistry registry, boolean daemon) Start a HTTP server serving Prometheus metrics from the given registry. -
Method Summary
Modifier and TypeMethodDescriptionint
getPort()
Gets the port number.parseQuery
(String query) protected static boolean
shouldUseCompression
(com.sun.net.httpserver.HttpExchange exchange) private void
start
(boolean daemon) Start a HTTP server by making sure that its background thread inherit proper daemon flag.void
stop()
Stop the HTTP server.
-
Field Details
-
server
protected final com.sun.net.httpserver.HttpServer server -
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 givenHttpServer
. ThehttpServer
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
Start a HTTP server serving Prometheus metrics from the given registry using non-daemon threads.- Throws:
IOException
-
HTTPServer
Start a HTTP server serving the default Prometheus registry.- Throws:
IOException
-
HTTPServer
Start a HTTP server serving the default Prometheus registry using non-daemon threads.- Throws:
IOException
-
HTTPServer
Start a HTTP server serving the default Prometheus registry.- Throws:
IOException
-
HTTPServer
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
- 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.
-