Class MetricMetadata

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

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

    • name

      private final String name
      Name without suffix.

      For example, the name for a counter "http_requests_total" is "http_requests". The name of an info called "jvm_info" is "jvm".

      We allow dots in label names. Dots are automatically replaced with underscores in Prometheus exposition formats. However, if metrics from this library are exposed in OpenTelemetry format dots are retained.

      See MetricMetadata(String, String, Unit) for more info on naming conventions.

    • prometheusName

      private final String prometheusName
      Same as name that all invalid char (without Unicode support) are replaced by _

      Multiple metrics with the same prometheusName are not allowed, because they would end up in the same time series in Prometheus if EscapingScheme.UNDERSCORE_ESCAPING or EscapingScheme.DOTS_ESCAPING is used.

    • help

      private final String help
    • unit

      private final Unit unit
  • Constructor Details

  • 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.

    • getHelp

      public String getHelp()
    • hasUnit

      public boolean hasUnit()
    • getUnit

      public Unit getUnit()
    • validate

      private void validate()
    • escape

      MetricMetadata escape(EscapingScheme escapingScheme)