Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class Metrics

  1. Object
  2. 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

public static Counter counter(String name, String description, String unit)A counter; the same one for the same name.
public static Counter upDownCounter(String name, String description, String unit)A counter that can go down too – items in a queue, open sessions.
public static Histogram histogram(String name, String description, String unit)A histogram with the default bucket boundaries, which suit milliseconds.
public static Histogram histogram(String name, String description, String unit, double[] bounds, String[] labels)A histogram with the given bucket boundaries, ascending, and label keys (up to three), or null for either default.
public static Gauge gauge(String name, String description, String unit, Gauge.Source source)A gauge read from source when metrics are collected.
public static Gauge gauge(String name, String description, String unit, Gauge.MultiSource source)A gauge with several labelled values.
public static synchronized List instruments()Every instrument, in registration order.
public static synchronized Instrument get(String name)The instrument called name, or null.
public static long startTimeMillis()When this process’s metrics started counting, for cumulative points.
public static Map snapshot()Every instrument and its points, for the management endpoint and MCP: name -> {kind, description, unit, points}.
public static String prometheus()Every instrument in the Prometheus text exposition format.

Inherited methods

Method details

counter

public static Counter counter(String name, String description, String unit)
A counter; the same one for the same name.

upDownCounter

public static Counter upDownCounter(String name, String description, String unit)
A counter that can go down too – items in a queue, open sessions.

histogram

public static Histogram histogram(String name, String description, String unit)
A histogram with the default bucket boundaries, which suit milliseconds.

histogram

public static Histogram histogram(String name, String description, String unit, double[] bounds, String[] labels)
A histogram with the given bucket boundaries, ascending, and label keys (up to three), or null for either default.

gauge

public static Gauge gauge(String name, String description, String unit, Gauge.Source source)
A gauge read from 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)
A gauge with several labelled values. See Gauge.MultiSource.

instruments

public static synchronized List instruments()
Every instrument, in registration order.

get

public static synchronized Instrument get(String name)
The instrument called name, or null.

startTimeMillis

public static long startTimeMillis()
When this process’s metrics started counting, for cumulative points.

snapshot

public static Map snapshot()
Every instrument and its points, for the management endpoint and MCP: name -> {kind, description, unit, points}.

prometheus

public static String prometheus()
Every instrument in the Prometheus text exposition format.