Module io.prometheus.metrics.model
Class PrometheusNaming
Object
PrometheusNaming
Utility for Prometheus Metric and Label naming.
Note that this library allows dots in metric and label names. Dots will automatically be replaced with underscores in Prometheus exposition formats. However, if metrics are exposed in OpenTelemetry format the dots are retained.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisValidLabelName(String name) static booleanisValidMetricName(String name) Test if a metric name is valid.static StringprometheusName(String name) Get the metric or label name that is used in Prometheus exposition format.static StringsanitizeLabelName(String labelName) Convert an arbitrary string to a name whereisValidLabelName(name)is true.static StringsanitizeMetricName(String metricName) Convert an arbitrary string to a name whereisValidMetricName(name)is true.
-
Constructor Details
-
PrometheusNaming
public PrometheusNaming()
-
-
Method Details
-
isValidMetricName
Test if a metric name is valid. Rules:- The name must match
METRIC_NAME_PATTERN. - The name MUST NOT end with one of the
RESERVED_METRIC_NAME_SUFFIXES.
Unit, the metric name SHOULD end with the unit as a suffix. Note that OpenMetrics requires metric names to have their unit as suffix, and we implement this inprometheus-metrics-core. However,prometheus-metrics-modeldoes not enforce Unit suffixes.Example: If you create a Counter for a processing time with Unit
SECONDS, the name should beprocessing_time_seconds. When exposed in OpenMetrics Text format, this will be represented as two values:processing_time_seconds_totalfor the counter value, and the optionalprocessing_time_seconds_createdtimestamp.Use
sanitizeMetricName(String)to convert arbitrary Strings to valid metric names. - The name must match
-
isValidLabelName
-
prometheusName
Get the metric or label name that is used in Prometheus exposition format.- Parameters:
name- must be a valid metric or label name, i.e.isValidMetricName(name)orisValidLabelName(name)must be true.- Returns:
- the name with dots replaced by underscores.
-
sanitizeMetricName
Convert an arbitrary string to a name whereisValidMetricName(name)is true. -
sanitizeLabelName
Convert an arbitrary string to a name whereisValidLabelName(name)is true.
-