Class MetricsHttpServer
java.lang.Object
com.loomcache.server.metrics.MetricsHttpServer
- All Implemented Interfaces:
AutoCloseable
Simple HTTP server that exposes Micrometer metrics in Prometheus text exposition format or JSON.
Starts an HTTP server on a configurable port (default 9090) and serves: - /metrics — all metrics (Prometheus text format by default, JSON with ?format=json) - /metrics/raft — Raft consensus metrics only - /metrics/network — TCP network metrics only - /metrics/datastructures — data structure operation counts only
Supports basic HTTP authentication via loomcache.metrics.auth.username/password config.
Thread-safe and AutoCloseable for easy resource management.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault bind address is loopback-only to avoid exposing metrics off-host by default. -
Constructor Summary
ConstructorsConstructorDescriptionMetricsHttpServer(io.micrometer.core.instrument.MeterRegistry meterRegistry) Create a MetricsHttpServer with default port 9090.MetricsHttpServer(io.micrometer.core.instrument.MeterRegistry meterRegistry, int port) Create a MetricsHttpServer with the given MeterRegistry on the specified port.MetricsHttpServer(io.micrometer.core.instrument.MeterRegistry meterRegistry, int port, @Nullable String authUsername, @Nullable String authPassword) Create a MetricsHttpServer with the given MeterRegistry on the specified port with auth credentials.MetricsHttpServer(io.micrometer.core.instrument.MeterRegistry meterRegistry, int port, String bindAddress, @Nullable String authUsername, @Nullable String authPassword) Create a MetricsHttpServer with the given MeterRegistry on the specified port and bind address. -
Method Summary
-
Field Details
-
DEFAULT_BIND_ADDRESS
Default bind address is loopback-only to avoid exposing metrics off-host by default.- See Also:
-
-
Constructor Details
-
MetricsHttpServer
public MetricsHttpServer(io.micrometer.core.instrument.MeterRegistry meterRegistry, int port, String bindAddress, @Nullable String authUsername, @Nullable String authPassword) throws IOException Create a MetricsHttpServer with the given MeterRegistry on the specified port and bind address.- Parameters:
meterRegistry- the MeterRegistry to expose metrics from (must not be null)port- the port to listen on (must be > 0)bindAddress- the address to bind to (e.g. "0.0.0.0" for all interfaces, "localhost" for loopback only)authUsername- optional username for HTTP Basic Auth (null to disable)authPassword- optional password for HTTP Basic Auth (null to disable)- Throws:
IOException- if the HTTP server fails to bind to the portNullPointerException- if meterRegistry or bindAddress is nullIllegalArgumentException- if port is invalid
-
MetricsHttpServer
public MetricsHttpServer(io.micrometer.core.instrument.MeterRegistry meterRegistry, int port, @Nullable String authUsername, @Nullable String authPassword) throws IOException Create a MetricsHttpServer with the given MeterRegistry on the specified port with auth credentials. Binds to loopback only by default.- Parameters:
meterRegistry- the MeterRegistry to expose metrics from (must not be null)port- the port to listen on (must be > 0)authUsername- optional username for HTTP Basic Auth (null to disable)authPassword- optional password for HTTP Basic Auth (null to disable)- Throws:
IOException- if the HTTP server fails to bind to the portNullPointerException- if meterRegistry is nullIllegalArgumentException- if port is invalid
-
MetricsHttpServer
public MetricsHttpServer(io.micrometer.core.instrument.MeterRegistry meterRegistry, int port) throws IOException Create a MetricsHttpServer with the given MeterRegistry on the specified port. Binds to loopback only by default, no authentication.- Parameters:
meterRegistry- the MeterRegistry to expose metrics from (must not be null)port- the port to listen on- Throws:
IOException- if the HTTP server fails to bind to the portNullPointerException- if meterRegistry is null
-
MetricsHttpServer
public MetricsHttpServer(io.micrometer.core.instrument.MeterRegistry meterRegistry) throws IOException Create a MetricsHttpServer with default port 9090. Binds to loopback only by default, no authentication.- Parameters:
meterRegistry- the MeterRegistry to expose metrics from (must not be null)- Throws:
IOException- if the HTTP server fails to bind to the portNullPointerException- if meterRegistry is null
-
-
Method Details
-
start
public void start()Start the HTTP server. -
stop
public void stop()Stop the HTTP server. -
isRunning
public boolean isRunning()Check if the server is running.- Returns:
- true if the server is running
-
close
public void close()Close the server (AutoCloseable implementation).- Specified by:
closein interfaceAutoCloseable
-