Prometheus Consul Service Discovery Missing Targets Fix
In this tutorial, you'll learn about Prometheus Consul Service Discovery Missing Targets Fix. We cover key concepts, practical examples, and best practices.
Your Prometheus Consul service discovery returns no targets — consul_sd_configs is configured but returns zero metrics. The Consul server is unreachable, the service names are wrong, or the datacenter does not contain the expected services.
The Problem
scrape_configs:
- job_name: 'consul-services'
consul_sd_configs:
- server: 'localhost:8500'
0 targets discovered
Prometheus can reach Consul at localhost:8500 but no services are found, or Consul is not running on that address.
Step-by-Step Fix
1. Verify Consul connectivity
# Check Consul is running
consul members
# List registered services
consul catalog services
# Check service health
consul catalog services -tags
# Test API
curl http://localhost:8500/v1/catalog/services
2. Configure service names
scrape_configs:
- job_name: 'consul-services'
consul_sd_configs:
- server: 'localhost:8500'
datacenter: 'dc1'
services:
- 'web'
- 'api'
- 'database'
3. Filter by tags
scrape_configs:
- job_name: 'consul-services'
consul_sd_configs:
- server: 'localhost:8500'
tags:
- 'prometheus'
- 'production'
4. Configure Consul agent with Prometheus health check
{
"service": {
"name": "web",
"port": 8080,
"tags": ["prometheus", "production"],
"check": {
"http": "http://localhost:8080/health",
"interval": "10s"
}
}
}
5. Use Consul SD with relabeling
scrape_configs:
- job_name: 'consul-services'
consul_sd_configs:
- server: 'localhost:8500'
datacenter: 'dc1'
relabel_configs:
# Keep only services with prometheus tag
- source_labels: [__meta_consul_tags]
regex: '.*prometheus.*'
action: keep
# Use service name as job label
- source_labels: [__meta_consul_service]
target_label: job
# Use service address and port
- source_labels: [__meta_consul_service_address, __meta_consul_service_port]
separator: ':'
target_label: __address__
Expected output:
Discovered targets: 12
web (10.0.0.1:8080) — service=web, dc=dc1
api (10.0.0.2:8080) — service=api, dc=dc1
database (10.0.0.3:5432) — service=database, dc=dc1
Prevention Tips
- Verify Consul API access from Prometheus server
- Register services in Consul with meaningful tags including
<a href="/devops/prometheus-grafana/">prometheus</a> - Use specific service names in
consul_sd_configsto limit scope - Use relabeling to map Consul metadata to cleaner Prometheus labels
- Monitor
<a href="/devops/prometheus-grafana/">Prometheus</a>_sd_consul_rpc_duration_secondsfor SD latency
Common Mistakes with consul sd
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists - Forgetting
deriving (Show, Eq)on custom data types needed for debugging
These mistakes appear frequently in real-world PROMETHEUS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro