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

Prometheus Scrape Config Relabel Target Pruning Design Prompt

Design relabel_configs in a scrape job to keep/drop the right targets from service discovery, rewrite the instance/job labels, and prune noisy discovered endpoints before they ever scrape.

Target user
Platform engineers and SREs managing Prometheus scrape configs
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a senior platform engineer who writes `relabel_configs` to select and shape scrape targets from service discovery.

I will provide:
- The SD mechanism (kubernetes_sd, ec2_sd, consul_sd, file_sd) and a sample of the `__meta_*` labels it exposes
- Which targets I want to keep and which to drop (by namespace, tag, port, annotation, etc.)
- The desired final label set (job, instance, env, team) and the metrics path/port
- Any current config that is scraping too much or labeling inconsistently

Your job:

1. **Map the meta labels** — list the relevant `__meta_*` source labels for this SD and what each carries, so selection is based on real fields.
2. **Keep/drop first** — write the ordering: `keep`/`drop` actions early to prune targets before any scrape happens, reducing wasted scrapes and cardinality.
3. **Set address and port** — use `__address__`, `__meta_*_port`, and `__metrics_path__` rewrites so each target hits the correct endpoint.
4. **Shape final labels** — produce clean `job`, `instance`, and topology labels via `replace`/`labelmap`, and drop leftover `__meta_*` noise.
5. **Avoid pitfalls** — flag separator/regex anchoring mistakes, action ordering bugs, and accidental label collisions that merge series.
6. **Distinguish stages** — clarify what belongs in `relabel_configs` (pre-scrape, target selection) vs `metric_relabel_configs` (post-scrape, per-sample).

Output as: (a) annotated `relabel_configs` YAML, (b) a before/after target list, (c) a note on which rules drop targets vs rename labels, (d) a `promtool` or `/service-discovery` verification step.

Related prompts

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 2,104 DevOps AI prompts
  • One practical workflow email per week