Skip to main content

How to calculate usage patterns and data volume in Prometheus

Sample PromQL queries to understand ingestion rate, read query rate and total time series

Calculating Ingestion Rate

This query will calculate the per-minute ingestion rate by averaging the per-second ingestion rate over the past minute, as measured by the prometheus_tsdb_head_samples_appended_total metric. The result will be a single value representing the average number of samples ingested per minute over the past minute.

 rate(prometheus_tsdb_head_samples_appended_total[1m]) * 60

Calculating Read Query Rate

This query will calculate the per-minute query rate by averaging the per-second query rate over the past minute, as measured by the prometheus_http_requests_total metric for GET requests to the /api/v1/query endpoint. This endpoint is used for executing queries against the Prometheus database, so this metric represents the number of read queries executed by the server.

sum by (handler) (rate(prometheus_http_requests_total{handler="/api/v1/query"}[1m]) * 60)

Calculating Total Time Series

This query will count the number of distinct time series in the database, regardless of the metric or label values. The regular expression ".+" matches all series names, so this query effectively counts all series.

 count({__name__=~".+"})
tip

Note that counting the total number of time series can be resource-intensive for large databases, and may take some time to complete. Additionally, this query may return inaccurate results if the database is actively ingesting or deleting time series during the query.