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
-
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.
-
Prometheus Scrape Config & Service Discovery Prompt
Configure Prometheus scrape targets — kubernetes_sd, ec2_sd, file_sd, consul_sd, relabeling, scrape interval tuning.
-
Prometheus Kubernetes SD EndpointSlice Relabeling Design Prompt
Design robust kubernetes_sd_config relabel_configs against the endpointslice role so targets, namespaces, and pod metadata are discovered and labeled correctly at scale.
-
Prometheus Consul Service Discovery & Relabeling Prompt
Design and debug a consul_sd_configs scrape setup so services register cleanly, targets carry the right labels, and dead nodes drop out without stale series.
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.