metrics section defines the Prometheus metrics that queries will populate. Each metric is configured with a unique name as the key.
Metric Structure
Dictionary of metric configurations, keyed by metric name.Metric names must match the pattern
^[a-zA-Z_][a-zA-Z0-9_]*$ (start with letter or underscore, followed by letters, numbers, or underscores).Metric Fields
The Prometheus metric type.Valid values:
counter- A cumulative metric that only increasesgauge- A metric that can increase or decreasehistogram- Samples observations and counts them in configurable bucketssummary- Similar to histogram, provides quantiles over a sliding time windowenum- A metric that can take one of a set of string values
Human-readable description of the metric.This description is included in the Prometheus metric metadata.
List of label names for the metric.Labels allow the metric to be sliced and diced in different dimensions. Query results must include columns matching these label names.Constraints:
- If specified, must contain at least 1 label
- Label names must match the pattern
^[a-zA-Z_][a-zA-Z0-9_]*$
Type-Specific Fields
Histogram Fields
Bucket boundaries for histogram metrics.Required for:
histogram type metricsConstraints:- Must contain at least 1 value
- Values must be unique
- Values must be sorted in ascending order
- Values must be numeric (float)
Enum Fields
Valid state values for enum metrics.Required for:
Only valid for:
enum type metricsOnly valid for:
enum type metricsConstraints:- Must contain at least 1 state
- States must be unique
states on non-enum metrics will raise: ValueError: states can only be set for enum metricsCounter Fields
Whether to increment the counter by the query result value or set it directly.Only valid for:
counter type metricsWhen true, the value from the query is added to the current counter value. When false, the counter is set to the query value (useful when the query returns cumulative counts).Default: falseValidation: Setting increment: true on non-counter metrics will raise: ValueError: increment can only be set for counter metricsTime-Based Fields
Time after which metric series are removed if not updated.Valid for: All metric typesUseful for cleaning up metrics for entities that no longer exist (e.g., deleted users, removed servers).Format:
- Integer: seconds
- String: number followed by optional suffix (
s=seconds,m=minutes,h=hours,d=days)
- Must be a positive number
- Must match pattern
^[0-9]+[smhd]?$for string format
Metric Type Examples
Counter
Counters represent cumulative values that only increase (or reset to zero).Gauge
Gauges represent values that can go up or down.Histogram
Histograms sample observations and count them in configurable buckets.Summary
Summaries are similar to histograms but calculate quantiles on the client side.Enum
Enums represent metrics that can take one of a predefined set of string values.Complete Example
Validation Rules
The following validation rules are enforced on metric configurations:-
Type validation:
typemust be one of:counter,gauge,histogram,summary,enum
-
Label validation:
- Label names must match pattern
^[a-zA-Z_][a-zA-Z0-9_]*$ - If
labelsis specified, must contain at least 1 label
- Label names must match pattern
-
Histogram validation:
bucketsmust contain at least 1 value- Bucket values must be unique
- Bucket values must be sorted in ascending order
-
Enum validation:
statescan only be set forenumtype metricsstatesmust contain at least 1 value- State values must be unique
-
Counter validation:
incrementcan only be set totrueforcountertype metrics
-
Expiration validation:
- Must be a positive number
- String format must match
^[0-9]+[smhd]?$
Error Messages
Common validation errors:ValueError: states can only be set for enum metrics- Attempted to setstateson a non-enum metricValueError: increment can only be set for counter metrics- Attempted to setincrement: trueon a non-counter metricAssertionError: must not contain duplicate items- Duplicate values inbucketsorstatesAssertionError: items must be sorted- Bucket values are not in ascending orderAssertionError: must be a positive number- Invalid expiration value