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

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

    • MetricMetadata

      public MetricMetadata(String name)
    • MetricMetadata

      public MetricMetadata(String name, String help)
    • MetricMetadata

      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

      public MetricMetadata(String name, String expositionBaseName, @Nullable String help, @Nullable Unit unit)
      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

      public MetricMetadata(String name, String expositionBaseName, String originalName, @Nullable String help, @Nullable Unit unit)
      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

    • getName

      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

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

      This is used by Prometheus exposition formats.

    • getOriginalName

      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

      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

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

      @Nullable public String getHelp()
    • hasUnit

      public boolean hasUnit()
    • getUnit

      @Nullable public Unit getUnit()