Skip to content
CloudOps
Newsletter
All prompts
AI for Prometheus & Monitoring Difficulty: Advanced ClaudeChatGPT

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.
Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week