metrics section defines Prometheus metrics that queries can update. Metric names must be valid Prometheus metric identifiers.
Basic Configuration
Configuration Options
The type of the Prometheus metric.Available types:
counter: Value is incremented or set with each result from queriesgauge: Value is set with each result from querieshistogram: Each result from queries is added to observationssummary: Each result from queries is added to observationsenum: Value is set to one of predefined states with each result
An optional description of the metric. This appears in the Prometheus
/metrics endpoint and helps document what the metric represents.Optional list of label names to apply to the metric. Label names must match the pattern
^[a-zA-Z_][a-zA-Z0-9_]*$.When specified, queries updating the metric must return columns with names matching both the metric name and all label names.For
histogram metrics only. Defines the bucket boundaries for the histogram.- Must contain at least 1 value
- Values must be sorted in ascending order
- Values must be unique
- If not specified, Prometheus default buckets are used:
[.005, .01, .025, .05, .075, .1, .25, .5, .75, 1.0, 2.5, 5.0, 7.5, 10.0, +Inf]
For
enum metrics only. List of possible string values for the enum state.- Must contain at least 1 value
- Values must be unique
- Queries must return one of these exact states
The amount of time after which a metric series is cleared if no new value is collected.The value can be:
- An integer (interpreted as seconds)
- A string with suffix:
s(seconds),m(minutes),h(hours),d(days)
300, 5m, 24h, 7dLast report times are tracked independently for each set of label values, making this useful for metric series that only exist temporarily.For
counter metrics only. Controls whether to increment the counter by the query result or set it to the result.false(default): Counter is set to the value returned by the querytrue: Counter is incremented by the value returned by the query
Metric Types
Counter
Counters track cumulative values that only increase (or are reset to zero).Gauge
Gauges represent values that can go up or down.Histogram
Histograms sample observations and count them in configurable buckets.Histograms are useful for measuring request durations or response sizes where you want to analyze the distribution of values.
Summary
Summaries also sample observations but calculate configurable quantiles over a sliding time window.Summaries are similar to histograms but calculate quantiles on the client side. Use histograms when you need server-side aggregation across multiple instances.
Enum
Enums represent a state that can be one of a predefined set of string values.Labels
Labels add dimensions to metrics, allowing you to differentiate between different instances:All queries updating this metric will automatically include a
database label to identify which database the metric came from.Expiration
Use expiration to automatically clean up metric series that haven’t been updated:- Metrics are tied to ephemeral resources (sessions, temporary jobs)
- You want to avoid unbounded cardinality growth
- Series naturally expire after some time
Complete Examples
PostgreSQL Connection Stats
Application Metrics
Business Metrics
Reserved Metric Names
The following metric names are reserved for built-in metrics and cannot be used:database_errorsqueriesquery_intervalquery_latencyquery_timestamp
Reserved Label Names
Thedatabase label is automatically added to all metrics and cannot be used in your custom labels. If you configure database-level labels, those label names are also reserved and cannot be used in metric definitions.