@@ -142,13 +142,15 @@ static ThreadFactory defaultThreadFactory(boolean daemon) {
142142 protected final HttpServer server ;
143143 protected final ExecutorService executorService ;
144144
145-
146145 /**
147- * Start a HTTP server serving Prometheus metrics from the given registry.
146+ * Start a HTTP server serving Prometheus metrics from the given registry using the given {@link HttpServer}.
147+ * The {@code httpServer} is expected to already be bound to an address
148148 */
149- public HTTPServer (InetSocketAddress addr , CollectorRegistry registry , boolean daemon ) throws IOException {
150- server = HttpServer .create ();
151- server .bind (addr , 3 );
149+ public HTTPServer (HttpServer httpServer , CollectorRegistry registry , boolean daemon ) throws IOException {
150+ if (httpServer .getAddress () == null )
151+ throw new IllegalArgumentException ("HttpServer hasn't been bound to an address" );
152+
153+ server = httpServer ;
152154 HttpHandler mHandler = new HTTPMetricHandler (registry );
153155 server .createContext ("/" , mHandler );
154156 server .createContext ("/metrics" , mHandler );
@@ -157,6 +159,13 @@ public HTTPServer(InetSocketAddress addr, CollectorRegistry registry, boolean da
157159 start (daemon );
158160 }
159161
162+ /**
163+ * Start a HTTP server serving Prometheus metrics from the given registry.
164+ */
165+ public HTTPServer (InetSocketAddress addr , CollectorRegistry registry , boolean daemon ) throws IOException {
166+ this (HttpServer .create (addr , 3 ), registry , daemon );
167+ }
168+
160169 /**
161170 * Start a HTTP server serving Prometheus metrics from the given registry using non-daemon threads.
162171 */
0 commit comments