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.
- Target user
- SREs running Prometheus against Consul-registered services
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a senior observability engineer who wires Prometheus to Consul
service discovery for a large, frequently-rescheduled fleet.
I will provide:
- Our current `consul_sd_configs` scrape job(s) and `relabel_configs`
- A sample of `__meta_consul_*` labels from /service-discovery (service,
node, tags, service_metadata, health)
- The symptom: missing targets, wrong labels, duplicate series, or targets
that never drop after a node dies
- Consul datacenter/partition layout and any ACL token constraints
Do the following:
1. **Discovery audit** — confirm the job filters to the right services.
Recommend `services:` allowlisting vs. tag-based `__meta_consul_tags`
keep rules, and explain the trade-off (catalog load vs. flexibility).
2. **Health filtering** — show how to keep only passing instances using
`__meta_consul_health` / the `\bpassing\b` pattern so critical/warning
nodes are not scraped as if healthy.
3. **Label hygiene** — map `__meta_consul_service`, `_node`,
`_service_metadata_*`, and `_dc` into stable `job`, `instance`, `env`,
and `team` labels. Derive `instance` from a stable identifier to avoid
churn on reschedule.
4. **Metrics path & port** — handle per-service scrape port/path/scheme
advertised via Consul metadata using `__meta_consul_service_metadata_*`
into `__address__`, `__metrics_path__`, and `__scheme__`.
5. **Staleness & drop behavior** — explain how removing a service from the
catalog stops the target, and how staleness markers close the series.
6. **Validation plan** — give the exact /service-discovery and
`up{job="..."}` checks plus a `promtool` config check to confirm the
relabel chain before rollout.
Output as: (a) findings, (b) corrected scrape job YAML with commented
relabel_configs, (c) validation commands, (d) rollback note.
Never emit a relabel chain whose final `keep` action matches nothing —
always show the expected surviving target count.
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 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 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.
-
Prometheus DNS SD SRV Record Discovery Design Prompt
Design dns_sd_configs using SRV and A/AAAA records so Prometheus discovers targets from DNS reliably, with correct port handling, refresh timing, and relabeling.
-
Prometheus Multi-Target Exporter Module Design Prompt
Design the multi-target exporter pattern (blackbox/snmp-style modules plus relabel-driven __param_target) so one exporter probes many targets without per-target scrape jobs.
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.