Package io.prometheus.client.exporter
Class HTTPServer
- java.lang.Object
-
- io.prometheus.client.exporter.HTTPServer
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class HTTPServer extends java.lang.Object implements java.io.CloseableExpose 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.BuilderWe keep the original constructors ofHTTPServerfor compatibility, but new configuration parameters likesampleNameFiltermust be configured using the Builder.static classHTTPServer.HTTPMetricHandlerHandles Metrics collections from the given registry.private static classHTTPServer.LocalByteArray(package private) static classHTTPServer.NamedDaemonThreadFactory
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.ExecutorServiceexecutorServiceprotected com.sun.net.httpserver.HttpServerserver
-
Constructor Summary
Constructors Modifier Constructor Description HTTPServer(int port)Start an HTTP server serving the default Prometheus registry using non-daemon threads.HTTPServer(int port, boolean daemon)Start an HTTP server serving the default Prometheus registry.HTTPServer(com.sun.net.httpserver.HttpServer httpServer, CollectorRegistry registry, boolean daemon)Start an HTTP server serving Prometheus metrics from the given registry using the givenHttpServer.HTTPServer(java.lang.String host, int port)Start an HTTP server serving the default Prometheus registry using non-daemon threads.HTTPServer(java.lang.String host, int port, boolean daemon)Start an HTTP server serving the default Prometheus registry.HTTPServer(java.net.InetSocketAddress addr, CollectorRegistry registry)Start an HTTP server serving Prometheus metrics from the given registry using non-daemon threads.HTTPServer(java.net.InetSocketAddress addr, CollectorRegistry registry, boolean daemon)Start an HTTP server serving Prometheus metrics from the given registry.privateHTTPServer(java.util.concurrent.ExecutorService executorService, com.sun.net.httpserver.HttpServer httpServer, CollectorRegistry registry, boolean daemon, Supplier<Predicate<java.lang.String>> sampleNameFilterSupplier, com.sun.net.httpserver.Authenticator authenticator)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()Stop the HTTPServer.intgetPort()Gets the port number.protected static java.util.Set<java.lang.String>parseQuery(java.lang.String query)protected static booleanshouldUseCompression(com.sun.net.httpserver.HttpExchange exchange)private voidstart(boolean daemon)Start an HTTP server by making sure that its background thread inherit proper daemon flag.voidstop()Deprecated.renamed to close(), so that the HTTPServer can be used in try-with-resources.
-
-
-
Constructor Detail
-
HTTPServer
public HTTPServer(com.sun.net.httpserver.HttpServer httpServer, CollectorRegistry registry, boolean daemon) throws java.io.IOExceptionStart an HTTP server serving Prometheus metrics from the given registry using the givenHttpServer. ThehttpServeris expected to already be bound to an address- Throws:
java.io.IOException
-
HTTPServer
public HTTPServer(java.net.InetSocketAddress addr, CollectorRegistry registry, boolean daemon) throws java.io.IOExceptionStart an HTTP server serving Prometheus metrics from the given registry.- Throws:
java.io.IOException
-
HTTPServer
public HTTPServer(java.net.InetSocketAddress addr, CollectorRegistry registry) throws java.io.IOExceptionStart an HTTP server serving Prometheus metrics from the given registry using non-daemon threads.- Throws:
java.io.IOException
-
HTTPServer
public HTTPServer(int port, boolean daemon) throws java.io.IOExceptionStart an HTTP server serving the default Prometheus registry.- Throws:
java.io.IOException
-
HTTPServer
public HTTPServer(int port) throws java.io.IOExceptionStart an HTTP server serving the default Prometheus registry using non-daemon threads.- Throws:
java.io.IOException
-
HTTPServer
public HTTPServer(java.lang.String host, int port, boolean daemon) throws java.io.IOExceptionStart an HTTP server serving the default Prometheus registry.- Throws:
java.io.IOException
-
HTTPServer
public HTTPServer(java.lang.String host, int port) throws java.io.IOExceptionStart an HTTP server serving the default Prometheus registry using non-daemon threads.- Throws:
java.io.IOException
-
HTTPServer
private HTTPServer(java.util.concurrent.ExecutorService executorService, com.sun.net.httpserver.HttpServer httpServer, CollectorRegistry registry, boolean daemon, Supplier<Predicate<java.lang.String>> sampleNameFilterSupplier, com.sun.net.httpserver.Authenticator authenticator)
-
-
Method Detail
-
shouldUseCompression
protected static boolean shouldUseCompression(com.sun.net.httpserver.HttpExchange exchange)
-
parseQuery
protected static java.util.Set<java.lang.String> parseQuery(java.lang.String query) throws java.io.IOException- Throws:
java.io.IOException
-
start
private void start(boolean daemon)
Start an HTTP server by making sure that its background thread inherit proper daemon flag.
-
stop
public void stop()
Deprecated.renamed to close(), so that the HTTPServer can be used in try-with-resources.Stop the HTTP server.
-
close
public void close()
Stop the HTTPServer.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
getPort
public int getPort()
Gets the port number.
-
-