Class MetricsManager

java.lang.Object
org.apache.juneau.rest.server.metrics.micrometer.MetricsManager

public class MetricsManager extends Object
Shared worker for the /metrics management endpoint: resolves a consumer-provided Micrometer MeterRegistry from the host bean store and renders a scrape payload.

Consistent with micrometer-core being a provided dependency and Juneau's explicit-over-magic stance, this adapter strictly consumes a consumer-provided registry — it never auto-registers a default. When no MeterRegistry bean is present it degrades cleanly (returns null, which the endpoints surface as HTTP 501).

A Prometheus text scrape is produced when the resolved registry is a PrometheusMeterRegistry. That type lives in the separate micrometer-registry-prometheus artifact which this module does not depend on, so its scrape() method is invoked reflectively — keeping the registry choice entirely the consumer's, with no extra dependency leaked here.

See Also:
Since:
10.0.0
  • Constructor Details

  • Method Details

    • resolveRegistry

      public io.micrometer.core.instrument.MeterRegistry resolveRegistry(RestContext context)
      Resolves the consumer-provided MeterRegistry from the host context's bean store.
      Parameters:
      context - The REST context whose bean store is searched. May be null.
      Returns:
      The registry, or null if none is registered (or the context is null).
    • scrape

      public String scrape(io.micrometer.core.instrument.MeterRegistry registry)
      Renders a Prometheus text scrape from the registry, if it is a PrometheusMeterRegistry.

      Invoked reflectively to avoid a hard dependency on micrometer-registry-prometheus. Returns null when the registry is null, is not a Prometheus registry, or does not expose a no-arg scrape() method — the endpoints surface that as HTTP 501.

      Parameters:
      registry - The resolved registry, or null.
      Returns:
      The Prometheus exposition text, or null if no scrape is available.