Package io.prometheus.client.exporter
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);
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHTTPServer.HTTPMetricHandlerHandles Metrics collections from the given registry.
-
Field Summary
Fields Modifier and Type Field Description protected ExecutorServiceexecutorServiceprotected com.sun.net.httpserver.HttpServerserver
-
Constructor Summary
Constructors Constructor Description HTTPServer(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, io.prometheus.client.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, io.prometheus.client.CollectorRegistry registry)Start a HTTP server serving Prometheus metrics from the given registry using non-daemon threads.HTTPServer(InetSocketAddress addr, io.prometheus.client.CollectorRegistry registry, boolean daemon)Start a HTTP server serving Prometheus metrics from the given registry.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetPort()Gets the port number.protected static Set<String>parseQuery(String query)protected static booleanshouldUseCompression(com.sun.net.httpserver.HttpExchange exchange)voidstop()Stop the HTTP server.
-
-
-
Field Detail
-
server
protected final com.sun.net.httpserver.HttpServer server
-
executorService
protected final ExecutorService executorService
-
-
Constructor Detail
-
HTTPServer
public HTTPServer(com.sun.net.httpserver.HttpServer httpServer, io.prometheus.client.CollectorRegistry registry, boolean daemon) throws IOException
Start a HTTP server serving Prometheus metrics from the given registry using the givenHttpServer. ThehttpServeris expected to already be bound to an address- Throws:
IOException
-
HTTPServer
public HTTPServer(InetSocketAddress addr, io.prometheus.client.CollectorRegistry registry, boolean daemon) throws IOException
Start a HTTP server serving Prometheus metrics from the given registry.- Throws:
IOException
-
HTTPServer
public HTTPServer(InetSocketAddress addr, io.prometheus.client.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 Detail
-
shouldUseCompression
protected static boolean shouldUseCompression(com.sun.net.httpserver.HttpExchange exchange)
-
parseQuery
protected static Set<String> parseQuery(String query) throws IOException
- Throws:
IOException
-
stop
public void stop()
Stop the HTTP server.
-
getPort
public int getPort()
Gets the port number.
-
-