Package io.prometheus.client.exporter
Class HTTPServer.Builder
- java.lang.Object
-
- io.prometheus.client.exporter.HTTPServer.Builder
-
- Enclosing class:
- HTTPServer
public static class HTTPServer.Builder extends java.lang.ObjectWe keep the original constructors ofHTTPServerfor compatibility, but new configuration parameters likesampleNameFiltermust be configured using the Builder.
-
-
Field Summary
Fields Modifier and Type Field Description private com.sun.net.httpserver.Authenticatorauthenticatorprivate booleandaemonprivate java.util.concurrent.ExecutorServiceexecutorServiceprivate java.lang.Stringhostnameprivate com.sun.net.httpserver.HttpsConfiguratorhttpsConfiguratorprivate com.sun.net.httpserver.HttpServerhttpServerprivate java.net.InetAddressinetAddressprivate java.net.InetSocketAddressinetSocketAddressprivate intportprivate CollectorRegistryregistryprivate Predicate<java.lang.String>sampleNameFilterprivate Supplier<Predicate<java.lang.String>>sampleNameFilterSupplier
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidassertNull(java.lang.Object o, java.lang.String msg)private voidassertZero(int i, java.lang.String msg)HTTPServerbuild()Build the HTTPServerHTTPServer.BuilderwithAuthenticator(com.sun.net.httpserver.Authenticator authenticator)Optional:Authenticatorto use to support authentication.HTTPServer.BuilderwithDaemonThreads(boolean daemon)By default, theHTTPServeruses non-daemon threads.HTTPServer.BuilderwithExecutorService(java.util.concurrent.ExecutorService executorService)Optional: ExecutorService used by thehttpServer.HTTPServer.BuilderwithHostname(java.lang.String hostname)Use this hostname to resolve the IP address to bind to.HTTPServer.BuilderwithHttpsConfigurator(com.sun.net.httpserver.HttpsConfigurator configurator)Optional:HttpsConfiguratorto use to support TLS/SSLHTTPServer.BuilderwithHttpServer(com.sun.net.httpserver.HttpServer httpServer)Use this httpServer.HTTPServer.BuilderwithInetAddress(java.net.InetAddress address)Bind to this IP address.HTTPServer.BuilderwithInetSocketAddress(java.net.InetSocketAddress address)Listen on this address.HTTPServer.BuilderwithPort(int port)Port to bind to.HTTPServer.BuilderwithRegistry(CollectorRegistry registry)Optional: Default isCollectorRegistry.defaultRegistry.HTTPServer.BuilderwithSampleNameFilter(Predicate<java.lang.String> sampleNameFilter)Optional: Only export time series wheresampleNameFilter.test(name)returns true.HTTPServer.BuilderwithSampleNameFilterSupplier(Supplier<Predicate<java.lang.String>> sampleNameFilterSupplier)Optional: Only export time series wheresampleNameFilter.test(name)returns true.
-
-
-
Field Detail
-
port
private int port
-
hostname
private java.lang.String hostname
-
inetAddress
private java.net.InetAddress inetAddress
-
inetSocketAddress
private java.net.InetSocketAddress inetSocketAddress
-
httpServer
private com.sun.net.httpserver.HttpServer httpServer
-
executorService
private java.util.concurrent.ExecutorService executorService
-
registry
private CollectorRegistry registry
-
daemon
private boolean daemon
-
sampleNameFilter
private Predicate<java.lang.String> sampleNameFilter
-
authenticator
private com.sun.net.httpserver.Authenticator authenticator
-
httpsConfigurator
private com.sun.net.httpserver.HttpsConfigurator httpsConfigurator
-
-
Method Detail
-
withPort
public HTTPServer.Builder withPort(int port)
Port to bind to. Must not be called together withwithInetSocketAddress(InetSocketAddress)orwithHttpServer(HttpServer). Default is 0, indicating that a random port will be selected.
-
withHostname
public HTTPServer.Builder withHostname(java.lang.String hostname)
Use this hostname to resolve the IP address to bind to. Must not be called together withwithInetAddress(InetAddress)orwithInetSocketAddress(InetSocketAddress)orwithHttpServer(HttpServer). Default is empty, indicating that the HTTPServer binds to the wildcard address.
-
withInetAddress
public HTTPServer.Builder withInetAddress(java.net.InetAddress address)
Bind to this IP address. Must not be called together withwithHostname(String)orwithInetSocketAddress(InetSocketAddress)orwithHttpServer(HttpServer). Default is empty, indicating that the HTTPServer binds to the wildcard address.
-
withInetSocketAddress
public HTTPServer.Builder withInetSocketAddress(java.net.InetSocketAddress address)
Listen on this address. Must not be called together withwithPort(int),withHostname(String),withInetAddress(InetAddress), orwithHttpServer(HttpServer).
-
withHttpServer
public HTTPServer.Builder withHttpServer(com.sun.net.httpserver.HttpServer httpServer)
Use this httpServer. ThehttpServeris expected to already be bound to an address. Must not be called together withwithPort(int), orwithHostname(String), orwithInetAddress(InetAddress), orwithInetSocketAddress(InetSocketAddress), orwithExecutorService(ExecutorService).
-
withExecutorService
public HTTPServer.Builder withExecutorService(java.util.concurrent.ExecutorService executorService)
Optional: ExecutorService used by thehttpServer. Must not be called together with thewithHttpServer(HttpServer).- Parameters:
executorService-- Returns:
-
withDaemonThreads
public HTTPServer.Builder withDaemonThreads(boolean daemon)
By default, theHTTPServeruses non-daemon threads. Set this totrueto run theHTTPServerwith daemon threads.
-
withSampleNameFilter
public HTTPServer.Builder withSampleNameFilter(Predicate<java.lang.String> sampleNameFilter)
Optional: Only export time series wheresampleNameFilter.test(name)returns true.Use this if the sampleNameFilter remains the same throughout the lifetime of the HTTPServer. If the sampleNameFilter changes during runtime, use
withSampleNameFilterSupplier(Supplier).
-
withSampleNameFilterSupplier
public HTTPServer.Builder withSampleNameFilterSupplier(Supplier<Predicate<java.lang.String>> sampleNameFilterSupplier)
Optional: Only export time series wheresampleNameFilter.test(name)returns true.Use this if the sampleNameFilter may change during runtime, like for example if you have a hot reload mechanism for your filter config. If the sampleNameFilter remains the same throughout the lifetime of the HTTPServer, use
withSampleNameFilter(Predicate)instead.
-
withRegistry
public HTTPServer.Builder withRegistry(CollectorRegistry registry)
Optional: Default isCollectorRegistry.defaultRegistry.
-
withAuthenticator
public HTTPServer.Builder withAuthenticator(com.sun.net.httpserver.Authenticator authenticator)
Optional:Authenticatorto use to support authentication.
-
withHttpsConfigurator
public HTTPServer.Builder withHttpsConfigurator(com.sun.net.httpserver.HttpsConfigurator configurator)
Optional:HttpsConfiguratorto use to support TLS/SSL
-
build
public HTTPServer build() throws java.io.IOException
Build the HTTPServer- Throws:
java.io.IOException
-
assertNull
private void assertNull(java.lang.Object o, java.lang.String msg)
-
assertZero
private void assertZero(int i, java.lang.String msg)
-
-