Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class Metrics
- Object
- 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 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.
Methods
Inherited methods
Method details
counter
public static Counter counter(String name, String description, String unit)upDownCounter
public static Counter upDownCounter(String name, String description, String unit)histogram
public static Histogram histogram(String name, String description, String unit)histogram
public static Histogram histogram(String name, String description, String unit, double[] bounds, String[] labels)gauge
public static Gauge gauge(String name, String description, String unit, Gauge.Source source)source when 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
public static Gauge gauge(String name, String description, String unit, Gauge.MultiSource source)Gauge.MultiSource.instruments
public static synchronized List instruments()get
public static synchronized Instrument get(String name)name, or null.startTimeMillis
public static long startTimeMillis()snapshot
public static Map snapshot()name -> {kind, description, unit, points}.prometheus
public static String prometheus()