Package io.prometheus.client.exporter
Class HTTPServer
java.lang.Object
io.prometheus.client.exporter.HTTPServer
- All Implemented Interfaces:
Closeable
,AutoCloseable
Expose Prometheus metrics using a plain Java HttpServer.
Example Usage:
HTTPServer server = new HTTPServer(1234);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
We keep the original constructors ofHTTPServer
for compatibility, but new configuration parameters likesampleNameFilter
must be configured using the Builder.static class
Handles Metrics collections from the given registry.private static class
(package private) static class
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionHTTPServer
(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
(HttpServer httpServer, CollectorRegistry registry, boolean daemon) Start an HTTP server serving Prometheus metrics from the given registry using the givenHttpServer
.HTTPServer
(String host, int port) Start an HTTP server serving the default Prometheus registry using non-daemon threads.HTTPServer
(String host, int port, boolean daemon) Start an HTTP server serving the default Prometheus registry.HTTPServer
(InetSocketAddress addr, CollectorRegistry registry) Start an HTTP server serving Prometheus metrics from the given registry using non-daemon threads.HTTPServer
(InetSocketAddress addr, CollectorRegistry registry, boolean daemon) Start an HTTP server serving Prometheus metrics from the given registry.private
HTTPServer
(ExecutorService executorService, HttpServer httpServer, CollectorRegistry registry, boolean daemon, Supplier<Predicate<String>> sampleNameFilterSupplier, Authenticator authenticator) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Stop the HTTPServer.int
getPort()
Gets the port number.parseQuery
(String query) protected static boolean
shouldUseCompression
(HttpExchange exchange) private void
start
(boolean daemon) Start an HTTP server by making sure that its background thread inherit proper daemon flag.void
stop()
Deprecated.renamed to close(), so that the HTTPServer can be used in try-with-resources.
-
Field Details
-
server
-
executorService
-
-
Constructor Details
-
HTTPServer
public HTTPServer(HttpServer httpServer, CollectorRegistry registry, boolean daemon) throws IOException Start an 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 an HTTP server serving Prometheus metrics from the given registry.- Throws:
IOException
-
HTTPServer
Start an HTTP server serving Prometheus metrics from the given registry using non-daemon threads.- Throws:
IOException
-
HTTPServer
Start an HTTP server serving the default Prometheus registry.- Throws:
IOException
-
HTTPServer
Start an HTTP server serving the default Prometheus registry using non-daemon threads.- Throws:
IOException
-
HTTPServer
Start an HTTP server serving the default Prometheus registry.- Throws:
IOException
-
HTTPServer
Start an HTTP server serving the default Prometheus registry using non-daemon threads.- Throws:
IOException
-
HTTPServer
private HTTPServer(ExecutorService executorService, HttpServer httpServer, CollectorRegistry registry, boolean daemon, Supplier<Predicate<String>> sampleNameFilterSupplier, Authenticator authenticator)
-
-
Method Details
-
shouldUseCompression
-
parseQuery
- Throws:
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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getPort
public int getPort()Gets the port number.
-