Package org.mockserver.metrics
Class Metrics
java.lang.Object
org.mockserver.metrics.Metrics
- Author:
- jamesdbloom
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclear()static voidclear(Metrics.Name name) static voidstatic voidstatic voidvoiddecrement(Metrics.Name name) voiddecrement(Action.Type type) static Integerget(Metrics.Name name) Per-action-type count of currently-active expectations.Per-fault-type count of currently-active service-scoped chaos profiles.static longgetAsyncMessageConsumedCount(String channel) Return the current async-messages-consumed count for the given channel, or 0 if metrics are disabled.static longgetAsyncMessagePublishedCount(String channel) Return the current async-messages-published count for the given channel, or 0 if metrics are disabled.static longgetHttpChaosInjectedCount(String faultType) Return the current chaos-injected count for the given fault type, or 0 if metrics are disabled.static longgetMcpToolCallCount(String toolName) Return the current MCP tool call count for the given tool name, or 0 if metrics are disabled.static longReturn the current slow-request count, or 0 if metrics are disabled.voidincrement(Metrics.Name name) voidincrement(Action.Type type) static voidincrementAsyncMessageConsumed(String channel) Increment the async-messages-consumed counter for the given channel.static voidincrementAsyncMessagePublished(String channel) Increment the async-messages-published counter for the given channel.static voidincrementHttpChaosInjected(String faultType) Increment the HTTP chaos injected counter for the given fault type.static voidincrementMcpToolCall(String toolName) Increment the MCP tool call counter for the given tool name.static voidIncrement the slow request counter.static voidobserveRequestDurationByMethodSeconds(double seconds, String method) Record a request-handling duration (seconds) in the per-method labeled histogram.static voidobserveRequestDurationSeconds(double seconds) Record a request-handling duration (seconds) in the latency histogram.static voidregisterOtelRequestDurationHistogram(io.opentelemetry.api.metrics.DoubleHistogram histogram) Register an OTel histogram for request duration.static voidReset the one-shot registration guard and null all lazily-registered metrics so that a subsequentnew Metrics(configuration)call re-registers them.voidset(Metrics.Name name, Integer value) static voidsetActiveExpectationsSupplier(Supplier<List<Expectation>> supplier) Set the supplier of active expectations.
-
Constructor Details
-
Metrics
-
-
Method Details
-
resetAdditionalMetricsForTesting
public static void resetAdditionalMetricsForTesting()Reset the one-shot registration guard and null all lazily-registered metrics so that a subsequentnew Metrics(configuration)call re-registers them. Also clears the default Prometheus registry.Public for cross-package test access (e.g. chaos injection tests); intended for test use only to guarantee deterministic test ordering.
-
clear
public static void clear() -
clear
-
set
-
get
-
registerOtelRequestDurationHistogram
public static void registerOtelRequestDurationHistogram(io.opentelemetry.api.metrics.DoubleHistogram histogram) Register an OTel histogram for request duration. Called byOtelMetricsExporterwhen OTLP export is enabled. -
observeRequestDurationSeconds
public static void observeRequestDurationSeconds(double seconds) Record a request-handling duration (seconds) in the latency histogram. No-op unless metrics are enabled (the histogram is null until then), so a caller on the request hot path pays nothing when metrics are off. -
observeRequestDurationByMethodSeconds
Record a request-handling duration (seconds) in the per-method labeled histogram. No-op unless route labels are enabled.- Parameters:
seconds- duration in secondsmethod- the HTTP method (e.g. "GET", "POST")
-
getSlowRequestCount
public static long getSlowRequestCount()Return the current slow-request count, or 0 if metrics are disabled. Used byOtelMetricsExporterto mirror the Prometheus counter via OTLP. -
incrementSlowRequestTotal
public static void incrementSlowRequestTotal()Increment the slow request counter. No-op unless metrics are enabled. -
getHttpChaosInjectedCount
Return the current chaos-injected count for the given fault type, or 0 if metrics are disabled. Used byOtelMetricsExporterto mirror the Prometheus counter via OTLP. -
incrementHttpChaosInjected
Increment the HTTP chaos injected counter for the given fault type. No-op when metrics are disabled (counter not registered) or faultType is null.- Parameters:
faultType- one of "drop", "error", "latency", "truncate", "malformed", "slow", "quota", or "graphql"
-
incrementMcpToolCall
Increment the MCP tool call counter for the given tool name. No-op when metrics are disabled (counter not registered) or toolName is null. Counts each completed tool invocation (called after the tool handler returns).- Parameters:
toolName- the name of the MCP tool invoked (from the bounded tool registry)
-
getMcpToolCallCount
Return the current MCP tool call count for the given tool name, or 0 if metrics are disabled. -
incrementAsyncMessagePublished
Increment the async-messages-published counter for the given channel. No-op when metrics are disabled (counter not registered) or channel is null. Called by the mockserver-async publish path (one increment per message published to a broker).- Parameters:
channel- the broker channel/topic the message was published to
-
incrementAsyncMessageConsumed
Increment the async-messages-consumed counter for the given channel. No-op when metrics are disabled (counter not registered) or channel is null. Called by the mockserver-async subscriber record path (one increment per message recorded from a broker).- Parameters:
channel- the broker channel/topic the message was consumed from
-
getAsyncMessagePublishedCount
Return the current async-messages-published count for the given channel, or 0 if metrics are disabled. -
getAsyncMessageConsumedCount
Return the current async-messages-consumed count for the given channel, or 0 if metrics are disabled. -
setActiveExpectationsSupplier
Set the supplier of active expectations. Called by HttpState at startup so the expectations-by-type GaugeWithCallback can read live state at scrape time without a core-to-netty dependency.- Parameters:
supplier- returns the list of currently-active expectations
-
getActiveExpectationCountByType
Per-action-type count of currently-active expectations. Backs themock_server_expectations_by_typePrometheus gauge; reads the live expectation list at scrape time via the registered supplier. -
getActiveServiceChaosCountByFaultType
Per-fault-type count of currently-active service-scoped chaos profiles. Backs themock_server_active_service_chaosPrometheus gauge and its OTLP mirror; reads the registry directly (not gated onmetricsEnabled, the gauge is only registered when metrics are on). -
increment
-
increment
-
decrement
-
decrement
-
clearRequestAndExpectationMetrics
public static void clearRequestAndExpectationMetrics() -
clearActionMetrics
public static void clearActionMetrics() -
clearWebSocketMetrics
public static void clearWebSocketMetrics()
-