Interface MetricsCollector
Soklet's standard implementation, available via defaultInstance(), supports detailed histogram collection,
connection accept/reject counters, immutable snapshots (via snapshot()), and provides Prometheus
(text format v0.0.4) / OpenMetrics (1.0) export helpers for convenience.
To disable metrics collection without a custom implementation, use disabledInstance().
If you prefer OpenTelemetry, Micrometer, or another metrics system for monitoring, you might choose to create your own implementation of this interface.
Example configuration:
SokletConfig config = SokletConfig.withHttpServer(HttpServer.fromPort(8080))
// This is already the default; specifying it here is optional
.metricsCollector(MetricsCollector.defaultInstance())
.build();
To disable metrics collection entirely, specify Soklet's no-op implementation:
SokletConfig config = SokletConfig.withHttpServer(HttpServer.fromPort(8080))
// Use this instead of null to disable metrics collection
.metricsCollector(MetricsCollector.disabledInstance())
.build();
All methods must be:
- Thread-safe — called concurrently from multiple request threads
- Non-blocking — should not perform I/O or acquire locks that might contend
- Failure-tolerant — exceptions are caught and logged, never break request handling
Example usage:
@GET("/metrics")
public MarshaledResponse getMetrics(@NonNull MetricsCollector metricsCollector) {
SnapshotTextOptions options = SnapshotTextOptions
.fromMetricsFormat(MetricsFormat.PROMETHEUS);
String body = metricsCollector.snapshotText(options).orElse(null);
if (body == null)
return MarshaledResponse.fromStatusCode(204);
return MarshaledResponse.withStatusCode(200)
.headers(Map.of("Content-Type", Set.of("text/plain; charset=UTF-8")))
.body(body.getBytes(StandardCharsets.UTF_8))
.build();
}
See https://www.soklet.com/docs/metrics-collection for detailed documentation.
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classA thread-safe histogram with fixed bucket boundaries.static final classImmutable snapshot of aMetricsCollector.Histogram.static final recordKey for metrics grouped by HTTP method and route match information.static final recordKey for metrics grouped by HTTP method, route match information, and status class (e.g. 2xx).static final recordKey for metrics grouped by MCP endpoint class, JSON-RPC method, and request outcome.static final recordKey for metrics grouped by MCP endpoint class and session termination reason.static final recordKey for metrics grouped by MCP endpoint class and stream termination reason.static enumText format to use forsnapshotText(SnapshotTextOptions).static final recordKey for request read failures grouped by reason.static final recordKey for request rejections grouped by reason.static enumIndicates whether a request was matched to aResourcePathDeclaration.static final classImmutable snapshot of collected metrics.static final classOptions for rendering a textual metrics snapshot.static final recordKey for metrics grouped by Server-Sent Event comment type, route match information, and drop reason.static final recordKey for metrics grouped by Server-Sent Event comment type, route match information, and enqueue outcome.static final recordKey for metrics grouped by Server-Sent Event comment type and route match information.static enumReasons a Server-Sent Event payload or comment was dropped before it could be written.static enumOutcomes for a Server-Sent Event enqueue attempt.static final recordKey for metrics grouped by Server-Sent Event route match information and drop reason.static final recordKey for metrics grouped by Server-Sent Event route match information and enqueue outcome.static final recordKey for metrics grouped by Server-Sent Event route match information and handshake failure reason.static final recordKey for metrics grouped by Server-Sent Event route match information.static final recordKey for metrics grouped by Server-Sent Event route match information and termination reason. -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull MetricsCollectorAcquires a threadsafeMetricsCollectorinstance with sensible defaults.default voiddidAcceptConnection(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress) Called after a server accepts a new TCP connection.default voiddidAcceptRequest(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress, @Nullable String requestTarget) Called after a request is accepted for application-level handling.default voiddidBroadcastSseComment(@NonNull ResourcePathDeclaration route, @NonNull SseComment.CommentType commentType, int attempted, int enqueued, int dropped) Called after a broadcast attempt for a Server-Sent Event comment payload.default voiddidBroadcastSseEvent(@NonNull ResourcePathDeclaration route, int attempted, int enqueued, int dropped) Called after a broadcast attempt for a Server-Sent Event payload.default voiddidCreateMcpSession(@NonNull Request request, @NonNull Class<? extends McpEndpoint> endpointClass, @NonNull String sessionId) Called after an MCP session is durably created.default voiddidDropSseComment(@NonNull SseConnection sseConnection, @NonNull SseComment sseComment, @NonNull MetricsCollector.SseEventDropReason reason, @Nullable Integer payloadBytes, @Nullable Integer queueDepth) Called after an SSE comment is dropped before it can be enqueued for delivery.default voiddidDropSseEvent(@NonNull SseConnection sseConnection, @NonNull SseEvent sseEvent, @NonNull MetricsCollector.SseEventDropReason reason, @Nullable Integer payloadBytes, @Nullable Integer queueDepth) Called after an SSE event is dropped before it can be enqueued for delivery.default voiddidEstablishMcpSseStream(@NonNull Request request, @NonNull Class<? extends McpEndpoint> endpointClass, @NonNull String sessionId) Called after an MCP GET stream is established.default voiddidEstablishSseConnection(@NonNull SseConnection sseConnection) Called after an SSE connection is established.default voiddidFailToAcceptConnection(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress, @NonNull ConnectionRejectionReason reason, @Nullable Throwable throwable) Called after a server fails to accept a new TCP connection.default voiddidFailToAcceptRequest(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress, @Nullable String requestTarget, @NonNull RequestRejectionReason reason, @Nullable Throwable throwable) Called when a request fails to be accepted before application-level handling begins.default voiddidFailToEstablishSseConnection(@NonNull Request request, @Nullable ResourceMethod resourceMethod, @NonNull SseConnection.HandshakeFailureReason reason, @Nullable Throwable throwable) Called if an SSE connection fails to establish.default voiddidFailToReadRequest(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress, @Nullable String requestTarget, @NonNull RequestReadFailureReason reason, @Nullable Throwable throwable) Called when a request could not be read or parsed into a validRequest.default voiddidFailToWriteResponse(@NonNull ServerType serverType, @NonNull Request request, @Nullable ResourceMethod resourceMethod, @NonNull MarshaledResponse marshaledResponse, @NonNull Duration responseWriteDuration, @NonNull Throwable throwable) Called after response data fails to write.default voiddidFailToWriteSseComment(@NonNull SseConnection sseConnection, @NonNull SseComment sseComment, @NonNull Duration writeDuration, @NonNull Throwable throwable, @Nullable Duration deliveryLag, @Nullable Integer payloadBytes, @Nullable Integer queueDepth) Called after an SSE comment fails to write.default voiddidFailToWriteSseEvent(@NonNull SseConnection sseConnection, @NonNull SseEvent sseEvent, @NonNull Duration writeDuration, @NonNull Throwable throwable, @Nullable Duration deliveryLag, @Nullable Integer payloadBytes, @Nullable Integer queueDepth) Called after an SSE event fails to write.default voiddidFinishMcpRequestHandling(@NonNull Request request, @NonNull Class<? extends McpEndpoint> endpointClass, @Nullable String sessionId, @NonNull String jsonRpcMethod, @Nullable McpJsonRpcRequestId jsonRpcRequestId, @NonNull McpRequestOutcome requestOutcome, @Nullable McpJsonRpcError jsonRpcError, @NonNull Duration duration, @NonNull List<@NonNull Throwable> throwables) Called after MCP JSON-RPC request handling finishes.default voiddidFinishRequestHandling(@NonNull ServerType serverType, @NonNull Request request, @Nullable ResourceMethod resourceMethod, @NonNull MarshaledResponse marshaledResponse, @NonNull Duration duration, @NonNull List<@NonNull Throwable> throwables) Called after a request finishes processing.default voiddidReadRequest(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress, @Nullable String requestTarget) Called when a request was successfully read or parsed into a validRequest.default voiddidStartMcpRequestHandling(@NonNull Request request, @NonNull Class<? extends McpEndpoint> endpointClass, @Nullable String sessionId, @NonNull String jsonRpcMethod, @Nullable McpJsonRpcRequestId jsonRpcRequestId) Called after a valid MCP JSON-RPC request begins handling.default voiddidStartRequestHandling(@NonNull ServerType serverType, @NonNull Request request, @Nullable ResourceMethod resourceMethod) Called as soon as a request is received and a Resource Method has been resolved to handle it.default voiddidTerminateMcpSession(@NonNull Class<? extends McpEndpoint> endpointClass, @NonNull String sessionId, @NonNull Duration sessionDuration, @NonNull McpSessionTerminationReason terminationReason, @Nullable Throwable throwable) Called after an MCP session is terminated.default voiddidTerminateMcpSseStream(@NonNull Request request, @NonNull Class<? extends McpEndpoint> endpointClass, @NonNull String sessionId, @NonNull Duration connectionDuration, @NonNull McpStreamTerminationReason terminationReason, @Nullable Throwable throwable) Called after an MCP GET stream is terminated.default voiddidTerminateSseConnection(@NonNull SseConnection sseConnection, @NonNull Duration connectionDuration, @NonNull SseConnection.TerminationReason terminationReason, @Nullable Throwable throwable) Called after an SSE connection is terminated.default voiddidWriteResponse(@NonNull ServerType serverType, @NonNull Request request, @Nullable ResourceMethod resourceMethod, @NonNull MarshaledResponse marshaledResponse, @NonNull Duration responseWriteDuration) Called after response data is written.default voiddidWriteSseComment(@NonNull SseConnection sseConnection, @NonNull SseComment sseComment, @NonNull Duration writeDuration, @Nullable Duration deliveryLag, @Nullable Integer payloadBytes, @Nullable Integer queueDepth) Called after an SSE comment is written.default voiddidWriteSseEvent(@NonNull SseConnection sseConnection, @NonNull SseEvent sseEvent, @NonNull Duration writeDuration, @Nullable Duration deliveryLag, @Nullable Integer payloadBytes, @Nullable Integer queueDepth) Called after an SSE event is written.static @NonNull MetricsCollectorAcquires a threadsafeMetricsCollectorinstance that performs no work.default voidreset()Resets any in-memory metrics state, if supported.default @NonNull Optional<MetricsCollector.Snapshot> snapshot()Returns a snapshot of metrics collected so far, if supported.Returns a text snapshot of metrics collected so far, if supported.default voidwillAcceptConnection(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress) Called when a server is about to accept a new TCP connection.default voidwillAcceptRequest(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress, @Nullable String requestTarget) Called when a request is about to be accepted for application-level handling.default voidwillEstablishSseConnection(@NonNull Request request, @Nullable ResourceMethod resourceMethod) Called before an SSE connection is established.default voidwillReadRequest(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress, @Nullable String requestTarget) Called when Soklet is about to read or parse a request into a validRequest.default voidwillTerminateSseConnection(@NonNull SseConnection sseConnection, @NonNull SseConnection.TerminationReason terminationReason, @Nullable Throwable throwable) Called before an SSE connection is terminated.default voidwillWriteResponse(@NonNull ServerType serverType, @NonNull Request request, @Nullable ResourceMethod resourceMethod, @NonNull MarshaledResponse marshaledResponse) Called before response data is written.default voidwillWriteSseComment(@NonNull SseConnection sseConnection, @NonNull SseComment sseComment) Called before an SSE comment is written.default voidwillWriteSseEvent(@NonNull SseConnection sseConnection, @NonNull SseEvent sseEvent) Called before an SSE event is written.
-
Method Details
-
willAcceptConnection
default void willAcceptConnection(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress) Called when a server is about to accept a new TCP connection.- Parameters:
serverType- the server type that is accepting the connectionremoteAddress- the best-effort remote address, ornullif unavailable
-
didAcceptConnection
default void didAcceptConnection(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress) Called after a server accepts a new TCP connection.- Parameters:
serverType- the server type that accepted the connectionremoteAddress- the best-effort remote address, ornullif unavailable
-
didFailToAcceptConnection
default void didFailToAcceptConnection(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress, @NonNull ConnectionRejectionReason reason, @Nullable Throwable throwable) Called after a server fails to accept a new TCP connection.- Parameters:
serverType- the server type that failed to accept the connectionremoteAddress- the best-effort remote address, ornullif unavailablereason- the failure reasonthrowable- an optional underlying cause, ornullif not applicable
-
willAcceptRequest
default void willAcceptRequest(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress, @Nullable String requestTarget) Called when a request is about to be accepted for application-level handling.- Parameters:
serverType- the server type that received the requestremoteAddress- the best-effort remote address, ornullif unavailablerequestTarget- the raw request target (path + query) if known, ornullif unavailable
-
didAcceptRequest
default void didAcceptRequest(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress, @Nullable String requestTarget) Called after a request is accepted for application-level handling.- Parameters:
serverType- the server type that received the requestremoteAddress- the best-effort remote address, ornullif unavailablerequestTarget- the raw request target (path + query) if known, ornullif unavailable
-
didFailToAcceptRequest
default void didFailToAcceptRequest(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress, @Nullable String requestTarget, @NonNull RequestRejectionReason reason, @Nullable Throwable throwable) Called when a request fails to be accepted before application-level handling begins.- Parameters:
serverType- the server type that received the requestremoteAddress- the best-effort remote address, ornullif unavailablerequestTarget- the raw request target (path + query) if known, ornullif unavailablereason- the rejection reasonthrowable- an optional underlying cause, ornullif not applicable
-
willReadRequest
default void willReadRequest(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress, @Nullable String requestTarget) Called when Soklet is about to read or parse a request into a validRequest.- Parameters:
serverType- the server type that received the requestremoteAddress- the best-effort remote address, ornullif unavailablerequestTarget- the raw request target (path + query) if known, ornullif unavailable
-
didReadRequest
default void didReadRequest(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress, @Nullable String requestTarget) Called when a request was successfully read or parsed into a validRequest.- Parameters:
serverType- the server type that received the requestremoteAddress- the best-effort remote address, ornullif unavailablerequestTarget- the raw request target (path + query) if known, ornullif unavailable
-
didFailToReadRequest
default void didFailToReadRequest(@NonNull ServerType serverType, @Nullable InetSocketAddress remoteAddress, @Nullable String requestTarget, @NonNull RequestReadFailureReason reason, @Nullable Throwable throwable) Called when a request could not be read or parsed into a validRequest.- Parameters:
serverType- the server type that received the requestremoteAddress- the best-effort remote address, ornullif unavailablerequestTarget- the raw request target (path + query) if known, ornullif unavailablereason- the failure reasonthrowable- an optional underlying cause, ornullif not applicable
-
didStartRequestHandling
default void didStartRequestHandling(@NonNull ServerType serverType, @NonNull Request request, @Nullable ResourceMethod resourceMethod) Called as soon as a request is received and a Resource Method has been resolved to handle it.- Parameters:
serverType- the server type that received the request
-
didFinishRequestHandling
default void didFinishRequestHandling(@NonNull ServerType serverType, @NonNull Request request, @Nullable ResourceMethod resourceMethod, @NonNull MarshaledResponse marshaledResponse, @NonNull Duration duration, @NonNull List<@NonNull Throwable> throwables) Called after a request finishes processing. -
willWriteResponse
default void willWriteResponse(@NonNull ServerType serverType, @NonNull Request request, @Nullable ResourceMethod resourceMethod, @NonNull MarshaledResponse marshaledResponse) Called before response data is written. -
didWriteResponse
default void didWriteResponse(@NonNull ServerType serverType, @NonNull Request request, @Nullable ResourceMethod resourceMethod, @NonNull MarshaledResponse marshaledResponse, @NonNull Duration responseWriteDuration) Called after response data is written. -
didFailToWriteResponse
default void didFailToWriteResponse(@NonNull ServerType serverType, @NonNull Request request, @Nullable ResourceMethod resourceMethod, @NonNull MarshaledResponse marshaledResponse, @NonNull Duration responseWriteDuration, @NonNull Throwable throwable) Called after response data fails to write. -
didCreateMcpSession
default void didCreateMcpSession(@NonNull Request request, @NonNull Class<? extends McpEndpoint> endpointClass, @NonNull String sessionId) Called after an MCP session is durably created. -
didTerminateMcpSession
default void didTerminateMcpSession(@NonNull Class<? extends McpEndpoint> endpointClass, @NonNull String sessionId, @NonNull Duration sessionDuration, @NonNull McpSessionTerminationReason terminationReason, @Nullable Throwable throwable) Called after an MCP session is terminated. -
didStartMcpRequestHandling
default void didStartMcpRequestHandling(@NonNull Request request, @NonNull Class<? extends McpEndpoint> endpointClass, @Nullable String sessionId, @NonNull String jsonRpcMethod, @Nullable McpJsonRpcRequestId jsonRpcRequestId) Called after a valid MCP JSON-RPC request begins handling. -
didFinishMcpRequestHandling
default void didFinishMcpRequestHandling(@NonNull Request request, @NonNull Class<? extends McpEndpoint> endpointClass, @Nullable String sessionId, @NonNull String jsonRpcMethod, @Nullable McpJsonRpcRequestId jsonRpcRequestId, @NonNull McpRequestOutcome requestOutcome, @Nullable McpJsonRpcError jsonRpcError, @NonNull Duration duration, @NonNull List<@NonNull Throwable> throwables) Called after MCP JSON-RPC request handling finishes. -
didEstablishMcpSseStream
default void didEstablishMcpSseStream(@NonNull Request request, @NonNull Class<? extends McpEndpoint> endpointClass, @NonNull String sessionId) Called after an MCP GET stream is established. -
didTerminateMcpSseStream
default void didTerminateMcpSseStream(@NonNull Request request, @NonNull Class<? extends McpEndpoint> endpointClass, @NonNull String sessionId, @NonNull Duration connectionDuration, @NonNull McpStreamTerminationReason terminationReason, @Nullable Throwable throwable) Called after an MCP GET stream is terminated. -
willEstablishSseConnection
default void willEstablishSseConnection(@NonNull Request request, @Nullable ResourceMethod resourceMethod) Called before an SSE connection is established. -
didEstablishSseConnection
Called after an SSE connection is established. -
didFailToEstablishSseConnection
default void didFailToEstablishSseConnection(@NonNull Request request, @Nullable ResourceMethod resourceMethod, @NonNull SseConnection.HandshakeFailureReason reason, @Nullable Throwable throwable) Called if an SSE connection fails to establish.- Parameters:
reason- the handshake failure reasonthrowable- an optional underlying cause, ornullif not applicable
-
willTerminateSseConnection
default void willTerminateSseConnection(@NonNull SseConnection sseConnection, @NonNull SseConnection.TerminationReason terminationReason, @Nullable Throwable throwable) Called before an SSE connection is terminated. -
didTerminateSseConnection
default void didTerminateSseConnection(@NonNull SseConnection sseConnection, @NonNull Duration connectionDuration, @NonNull SseConnection.TerminationReason terminationReason, @Nullable Throwable throwable) Called after an SSE connection is terminated. -
willWriteSseEvent
Called before an SSE event is written. -
didWriteSseEvent
default void didWriteSseEvent(@NonNull SseConnection sseConnection, @NonNull SseEvent sseEvent, @NonNull Duration writeDuration, @Nullable Duration deliveryLag, @Nullable Integer payloadBytes, @Nullable Integer queueDepth) Called after an SSE event is written.- Parameters:
sseConnection- the connection the event was written tosseEvent- the event that was writtenwriteDuration- how long it took to write the eventdeliveryLag- elapsed time between enqueue and write start, ornullif unknownpayloadBytes- size of the serialized payload in bytes, ornullif unknownqueueDepth- number of queued elements remaining at write time, ornullif unknown
-
didFailToWriteSseEvent
default void didFailToWriteSseEvent(@NonNull SseConnection sseConnection, @NonNull SseEvent sseEvent, @NonNull Duration writeDuration, @NonNull Throwable throwable, @Nullable Duration deliveryLag, @Nullable Integer payloadBytes, @Nullable Integer queueDepth) Called after an SSE event fails to write.- Parameters:
sseConnection- the connection the event was written tosseEvent- the event that was writtenwriteDuration- how long it took to attempt the writethrowable- the failure causedeliveryLag- elapsed time between enqueue and write start, ornullif unknownpayloadBytes- size of the serialized payload in bytes, ornullif unknownqueueDepth- number of queued elements remaining at write time, ornullif unknown
-
willWriteSseComment
default void willWriteSseComment(@NonNull SseConnection sseConnection, @NonNull SseComment sseComment) Called before an SSE comment is written. -
didWriteSseComment
default void didWriteSseComment(@NonNull SseConnection sseConnection, @NonNull SseComment sseComment, @NonNull Duration writeDuration, @Nullable Duration deliveryLag, @Nullable Integer payloadBytes, @Nullable Integer queueDepth) Called after an SSE comment is written.- Parameters:
sseConnection- the connection the comment was written tosseComment- the comment that was writtenwriteDuration- how long it took to write the commentdeliveryLag- elapsed time between enqueue and write start, ornullif unknownpayloadBytes- size of the serialized payload in bytes, ornullif unknownqueueDepth- number of queued elements remaining at write time, ornullif unknown
-
didFailToWriteSseComment
default void didFailToWriteSseComment(@NonNull SseConnection sseConnection, @NonNull SseComment sseComment, @NonNull Duration writeDuration, @NonNull Throwable throwable, @Nullable Duration deliveryLag, @Nullable Integer payloadBytes, @Nullable Integer queueDepth) Called after an SSE comment fails to write.- Parameters:
sseConnection- the connection the comment was written tosseComment- the comment that was writtenwriteDuration- how long it took to attempt the writethrowable- the failure causedeliveryLag- elapsed time between enqueue and write start, ornullif unknownpayloadBytes- size of the serialized payload in bytes, ornullif unknownqueueDepth- number of queued elements remaining at write time, ornullif unknown
-
didDropSseEvent
default void didDropSseEvent(@NonNull SseConnection sseConnection, @NonNull SseEvent sseEvent, @NonNull MetricsCollector.SseEventDropReason reason, @Nullable Integer payloadBytes, @Nullable Integer queueDepth) Called after an SSE event is dropped before it can be enqueued for delivery.- Parameters:
sseConnection- the connection the event was targetingsseEvent- the event that was droppedreason- the drop reasonpayloadBytes- size of the serialized payload in bytes, ornullif unknownqueueDepth- number of queued elements at drop time, ornullif unknown
-
didDropSseComment
default void didDropSseComment(@NonNull SseConnection sseConnection, @NonNull SseComment sseComment, @NonNull MetricsCollector.SseEventDropReason reason, @Nullable Integer payloadBytes, @Nullable Integer queueDepth) Called after an SSE comment is dropped before it can be enqueued for delivery.- Parameters:
sseConnection- the connection the comment was targetingsseComment- the comment that was droppedreason- the drop reasonpayloadBytes- size of the serialized payload in bytes, ornullif unknownqueueDepth- number of queued elements at drop time, ornullif unknown
-
didBroadcastSseEvent
default void didBroadcastSseEvent(@NonNull ResourcePathDeclaration route, int attempted, int enqueued, int dropped) Called after a broadcast attempt for a Server-Sent Event payload.- Parameters:
route- the route declaration that was broadcast toattempted- number of connections targetedenqueued- number of connections for which enqueue succeededdropped- number of connections for which enqueue failed
-
didBroadcastSseComment
default void didBroadcastSseComment(@NonNull ResourcePathDeclaration route, @NonNull SseComment.CommentType commentType, int attempted, int enqueued, int dropped) Called after a broadcast attempt for a Server-Sent Event comment payload.- Parameters:
route- the route declaration that was broadcast tocommentType- the comment typeattempted- number of connections targetedenqueued- number of connections for which enqueue succeededdropped- number of connections for which enqueue failed
-
snapshot
Returns a snapshot of metrics collected so far, if supported.- Returns:
- an optional metrics snapshot
-
snapshotText
default @NonNull Optional<String> snapshotText(@NonNull MetricsCollector.SnapshotTextOptions options) Returns a text snapshot of metrics collected so far, if supported.The default collector supports Prometheus (text format v0.0.4) and OpenMetrics (1.0) text exposition formats.
- Parameters:
options- the snapshot rendering options- Returns:
- a textual metrics snapshot, or
Optional.empty()if unsupported
-
reset
Resets any in-memory metrics state, if supported. -
defaultInstance
Acquires a threadsafeMetricsCollectorinstance with sensible defaults.This method is guaranteed to return a new instance.
- Returns:
- a
MetricsCollectorwith default settings
-
disabledInstance
Acquires a threadsafeMetricsCollectorinstance that performs no work.This method is useful when you want to explicitly disable metrics collection without writing your own implementation.
The returned instance is guaranteed to be a JVM-wide singleton.
- Returns:
- a no-op
MetricsCollector
-