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 Object
We keep the original constructors ofHTTPServerfor compatibility, but new configuration parameters likesampleNameFiltermust be configured using the Builder.
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.BuilderwithHostname(String hostname)Use this hostname to resolve the IP address to bind to.HTTPServer.BuilderwithHttpServer(com.sun.net.httpserver.HttpServer httpServer)Use this httpServer.HTTPServer.BuilderwithInetAddress(InetAddress address)Bind to this IP address.HTTPServer.BuilderwithInetSocketAddress(InetSocketAddress address)Listen on this address.HTTPServer.BuilderwithPort(int port)Port to bind to.HTTPServer.BuilderwithRegistry(io.prometheus.client.CollectorRegistry registry)Optional: Default isCollectorRegistry.defaultRegistry.HTTPServer.BuilderwithSampleNameFilter(io.prometheus.client.Predicate<String> sampleNameFilter)Optional: Only export time series wheresampleNameFilter.test(name)returns true.HTTPServer.BuilderwithSampleNameFilterSupplier(io.prometheus.client.Supplier<io.prometheus.client.Predicate<String>> sampleNameFilterSupplier)Optional: Only export time series wheresampleNameFilter.test(name)returns true.
-
-
-
Constructor Detail
-
Builder
public Builder()
-
-
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(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(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(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).
-
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(io.prometheus.client.Predicate<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(io.prometheus.client.Supplier<io.prometheus.client.Predicate<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(io.prometheus.client.CollectorRegistry registry)
Optional: Default isCollectorRegistry.defaultRegistry.
-
withAuthenticator
public HTTPServer.Builder withAuthenticator(com.sun.net.httpserver.Authenticator authenticator)
Optional:Authenticatorto use to support authentication.
-
build
public HTTPServer build() throws IOException
Build the HTTPServer- Throws:
IOException
-
-