Class Metrics
The server's metrics: every Instrument by name, and the ones the
server records about itself.
private static final Counter ORDERS = Metrics.counter("orders.placed",
"Orders accepted", "{order}");
...
ORDERS.increment();
Asking for a name twice answers the same instrument, so a static field initialized in two classes, or a server restarted in one process, shares it. Asking for an existing name as a different kind is refused.
What reads them: the OTLP exporter, when the build enables OpenTelemetry;
the management endpoint's metrics and prometheus views; and
the development MCP server. None of them is linked into a server whose build
does not ask for it, and an instrument nothing reads costs its own
recording and nothing more.
What the server records
Once enableServer(HttpServer, DataSource) has run -- the generated entry point calls it when
metrics are on -- every request is measured in
http.server.request.duration (milliseconds, by route template, method
and status), and the server's counters, the database pool, the task executors
and the process's memory are published as gauges.
-
Method Summary
Modifier and TypeMethodDescriptionstatic CounterA counter; the same one for the same name.static Gaugegauge(String name, String description, String unit, Gauge.MultiSource source) A gauge with several labelled values.static Gaugegauge(String name, String description, String unit, Gauge.Source source) A gauge read fromsourcewhen metrics are collected.static InstrumentThe instrument calledname, or null.static HistogramA histogram with the default bucket boundaries, which suit milliseconds.static HistogramA histogram with the given bucket boundaries, ascending, and label keys (up to three), or null for either default.static ListEvery instrument, in registration order.static StringEvery instrument in the Prometheus text exposition format.static Mapsnapshot()Every instrument and its points, for the management endpoint and MCP:name -> {kind, description, unit, points}.static longWhen this process's metrics started counting, for cumulative points.static CounterupDownCounter(String name, String description, String unit) A counter that can go down too -- items in a queue, open sessions.
-
Method Details
-
counter
-
upDownCounter
-
histogram
-
histogram
-
gauge
A gauge read fromsourcewhen metrics are collected. A gauge registered again under the same name REPLACES the old one, since its source is usually an object that has been replaced too -- a restarted server's pool. -
gauge
A gauge with several labelled values. SeeGauge.MultiSource. -
instruments
Every instrument, in registration order. -
get
The instrument calledname, or null. -
startTimeMillis
public static long startTimeMillis()When this process's metrics started counting, for cumulative points. -
snapshot
Every instrument and its points, for the management endpoint and MCP:name -> {kind, description, unit, points}. -
prometheus
Every instrument in the Prometheus text exposition format.
-