java.lang.Object
io.prometheus.metrics.model.snapshots.MetricMetadata

public final class MetricMetadata extends Object
Immutable container for metric metadata: name, help, unit.
  • Constructor Details

    • MetricMetadata

      @StableApi public MetricMetadata(String name)
    • MetricMetadata

      @StableApi public MetricMetadata(String name, String help)
    • MetricMetadata

      @StableApi public MetricMetadata(String name, @Nullable String help, @Nullable Unit unit)
      Constructor.
      Parameters:
      name - must not be null. isValidMetricName(name) must be true. Use PrometheusNaming.sanitizeMetricName(String) to convert arbitrary strings into valid names.
      help - optional. May be null.
      unit - optional. May be null.
    • MetricMetadata

      @StableApi @Deprecated public MetricMetadata(String name, String expositionBaseName, @Nullable String help, @Nullable Unit unit)
      Deprecated.
      Use builder() instead.
      Constructor with exposition base name.
      Parameters:
      name - the base name (with type suffixes stripped, e.g. "events" for a counter named "events_total")
      expositionBaseName - the name with unit suffix ensured and type suffix preserved, used by format writers for smart-append logic
      help - optional. May be null.
      unit - optional. May be null.
    • MetricMetadata

      @StableApi @Deprecated public MetricMetadata(String name, String expositionBaseName, String originalName, @Nullable String help, @Nullable Unit unit)
      Deprecated.
      Use builder() instead.
      Constructor with exposition base name and original name.
      Parameters:
      name - the base name (with type suffixes stripped, e.g. "events" for a counter named "events_total")
      expositionBaseName - the name with unit suffix ensured and type suffix preserved
      originalName - the raw name as provided by the user, before any modification
      help - optional. May be null.
      unit - optional. May be null.
  • Method Details

    • builder

      @StableApi public static MetricMetadata.Builder builder()
      Creates a builder for MetricMetadata.

      Use the builder instead of the multi-arg constructors for cleaner, more readable code:

      
       MetricMetadata.builder()
           .name("http_requests")
           .help("Total HTTP requests")
           .unit(Unit.BYTES)
           .counterSuffix(true)
           .build();
       
    • getName

      @StableApi public String getName()
      The name does not include the _total suffix for counter metrics or the _info suffix for Info metrics.

      The name may contain any Unicode chars. Use getPrometheusName() to get the name in legacy Prometheus format, i.e. with all dots and all invalid chars replaced by underscores.

    • getPrometheusName

      @StableApi public String getPrometheusName()
      Same as getName() but with all invalid characters and dots replaced by underscores.

      This is used by Prometheus exposition formats.

    • getOriginalName

      @StableApi public String getOriginalName()
      The original name as provided by the user, before any modification. For example, if the user called Counter.builder().name("req").unit(BYTES), this returns "req" while getName() returns "req_bytes" and getExpositionBaseName() returns "req_bytes".
    • getExpositionBaseName

      @StableApi public String getExpositionBaseName()
      The base name for exposition, with unit suffix ensured and type suffix preserved. For example, if the user called Counter.builder().name("events_total"), this returns "events_total" while getName() returns "events".
    • getExpositionBasePrometheusName

      @StableApi public String getExpositionBasePrometheusName()
      Same as getExpositionBaseName() but with all invalid characters and dots replaced by underscores.
    • getHelp

      @StableApi @Nullable public String getHelp()
    • hasUnit

      @StableApi public boolean hasUnit()
    • getUnit

      @StableApi @Nullable public Unit getUnit()