🚧 Work in Progress 🚧
dpm-finder
This repository contains a Python script designed to identify metrics in Prometheus that exceed a specified rate. It's particularly useful for detecting metrics with high data points per minute (DPM) rates, which can be indicative of issues or important trends.
The script can run in two modes:
- One-time execution: Calculate DPM and output results to files
- Prometheus exporter: Run as a server that exposes DPM metrics for Prometheus scraping
Overview
The dpm-finder script retrieves a list of all metrics from a Prometheus instance, calculates their data points per minute (DPM) rate using PromQL, and identifies metrics whose DPM exceeds a threshold. Results can be output to files or served via a Prometheus-compatible HTTP endpoint.
Functionality
The script does the following:
- Retrieves all metrics from a Prometheus instance using the
/api/v1/label/__name__/values endpoint.
- Filters metrics automatically to exclude:
- Components from verified classic histogram families with
_bucket, _count, and _sum
siblings, unless --include-histograms is set. Ambiguous suffixed metrics are retained.
- Metrics beginning with
grafana_ (Grafana internal metrics)
- Native histogram base metrics remain included because they are single first-class series,
not suffixed component series
- Handles Adaptive Metrics by inventorying stored aggregated series, reading applied rules,
and querying those series directly. If discovery misses a metric, an explicit Adaptive Metrics
422 response triggers the same query automatically.
- Calculates DPM rate for each metric using a PromQL query:
count_over_time({metric_name}[Nm])/N (where N is the configurable lookback window in minutes, default 10).
- Filters results based on a DPM threshold (metrics with DPM > 1 by default).
- Outputs results in various formats:
- One-time mode: CSV, JSON, text, or Prometheus exposition format files
- Exporter mode: Live Prometheus metrics endpoint at
/metrics
- Provides detailed logging with configurable verbosity levels for monitoring progress and debugging.
How To
1. Create .env with the following variables
Please note the prometheus endpoint should not have anything after .net.
See .env_example
PROMETHEUS_ENDPOINT=""
PROMETHEUS_USERNAME=""
PROMETHEUS_API_KEY=""
The API key requires both of these access-policy scopes:
metrics:read to list and query Prometheus metrics
adaptive-metrics-rules:read to discover applied Adaptive Metrics aggregation rules
Without adaptive-metrics-rules:read, the script can still inventory stored aggregated series and
retry an aggregated metric from its Prometheus 422 response, but it cannot inspect current rules.
2. Install all libraries from requirements.txt
python3 -m venv venv
source ./venv/bin/activate
python3 -m pip install -r requirements.txt
3. Run the script
One-time execution (traditional mode):
./dpm-finder.py -t 4 -f csv
Prometheus exporter mode:
./dpm-finder.py -e -p 9966
Use an existing GCX login
GCX mode runs every Prometheus query through the gcx executable, so the script does not need a
.env file or direct access-policy token. GCX remains responsible for its cross-platform config,
credential storage, authentication refresh, and datasource selection.
# Use the current GCX context and its configured Prometheus datasource
./dpm-finder.py --gcx -f json
# Select a context without changing the user's current GCX context
./dpm-finder.py --gcx --gcx-context robk -f json
# Override the configured Prometheus datasource when a context has more than one
./dpm-finder.py --gcx --gcx-context robk --gcx-datasource prometheus-uid -f json
The gcx executable must be on PATH. Use --gcx-binary /path/to/gcx for a custom location.
Adaptive Metrics rule discovery may require a separate GCX cloud login. If that lookup is not
authorised, the run continues using stored aggregated-series discovery and targeted 422 detection.
Docker Usage
The dpm-finder can be run as a Docker container for easy deployment and isolation.
Building the Docker Image
# Build the image
docker build -t dpm-finder:latest .
# Or build with a specific tag
docker build -t dpm-finder:v1.0.0 .
Running with Docker
Environment Variables
Set your Prometheus credentials as environment variables:
export PROMETHEUS_ENDPOINT="https://prometheus-prod-13-prod-us-east-0.grafana.net"
export PROMETHEUS_USERNAME="1234567"
export PROMETHEUS_API_KEY="glc_key-example-..."
Exporter Mode