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.

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

More Prometheus & Monitoring prompts & error guides

Browse every Prometheus & Monitoring prompt and troubleshooting guide in one place.

Free download · 368-page PDF

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.