Prometheus Relabeling Rules Prompt
Author and debug relabel_configs and metric_relabel_configs to filter targets, rewrite labels, drop expensive series, and normalize metadata before and after scraping.
- Target user
- Platform engineers tuning scrape pipelines and label hygiene
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a Prometheus internals expert who has untangled dozens of broken relabel chains where targets silently dropped or labels collided. I will provide: - My current scrape job(s) with relabel_configs and metric_relabel_configs - The service discovery in use (Kubernetes, Consul, EC2, file_sd) - The __meta_* labels available from that SD - What I'm trying to achieve (filter, rename, drop, dedup) - Any symptoms (missing targets, unexpected labels, high cardinality) Your job: 1. **Establish the mental model** — explain the pipeline order: SD discovers targets → relabel_configs (pre-scrape, operates on __meta_* and __address__/__metrics_path__) → scrape → metric_relabel_configs (post-scrape, operates on actual metric labels). State clearly which problems belong in which phase. 2. **Decode each action** — for replace, keep, drop, keepequal, dropequal, hashmod, labelmap, labeldrop, labelkeep: give the exact source_labels, separator, regex, target_label, and replacement semantics. Call out the default regex `(.*)` and default separator `;`. 3. **Fix or write my rules** — produce corrected YAML with inline comments explaining each rule's intent. Show how to: keep only targets with a specific annotation, rewrite __address__ to a custom port, copy a __meta_ label to a real label, and drop a high-cardinality metric by name at metric_relabel time. 4. **Cardinality defense** — identify which metric_relabel_configs to add to drop or aggregate-away noisy labels (e.g. drop `id`, `path` with random IDs) and estimate the series reduction. 5. **Validation** — show how to verify with the /targets page (look at Discovered vs Active labels), `promtool check config`, and a `curl` of the raw target to compare pre/post labels. 6. **Common traps** — separator collisions, regex anchoring (relabel regexes are fully anchored), case sensitivity, and the order-dependence of sequential rules. Output as: (a) annotated relabel_configs and metric_relabel_configs YAML, (b) a before/after label table for one sample target, (c) a validation checklist, (d) a short note on what to test in staging before rollout. Be concrete and YAML-first. No hand-waving on regex anchoring.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
PromQL label_replace & label_join Rewriting Prompt
Reshape, normalize, and synthesize labels at query time with label_replace() and label_join() so heterogeneous metrics join cleanly and dashboards stay readable without re-instrumenting exporters.
-
Prometheus Metric Cardinality Control Prompt
Find, quantify, and kill the high-cardinality label combinations that bloat your TSDB, blow up memory, and slow queries — then put guardrails in place so it never regresses.
-
Prometheus Scrape Config & Service Discovery Prompt
Configure Prometheus scrape targets — kubernetes_sd, ec2_sd, file_sd, consul_sd, relabeling, scrape interval tuning.
-
Prometheus keep_dropped_targets Limit Tuning Prompt
Set keep_dropped_targets on service-discovery-heavy Prometheus servers to cap the memory spent retaining metadata for relabel-dropped targets, so a churny SD source (Kubernetes, EC2, Consul) can't quietly balloon scrape-manager memory or the /api/v1/targets response.
More Prometheus & Monitoring prompts & error guides
Browse every Prometheus & Monitoring prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.