Skip to content

Prometheus Consul Service Discovery Missing Targets Fix

DodaTech Updated 2026-06-24 2 min read

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_configs to limit scope
  • Use relabeling to map Consul metadata to cleaner Prometheus labels
  • Monitor <a href="/devops/prometheus-grafana/">Prometheus</a>_sd_consul_rpc_duration_seconds for SD latency

Common Mistakes with consul sd

  1. Misunderstanding that String is [Char] with poor performance for large text operations
  2. Using foldl instead of foldl' causing stack overflow on large lists
  3. 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

### How does Prometheus discover Consul services?

Prometheus queries the Consul catalog API (/v1/catalog/services and /v1/catalog/service/:name) to discover services. It then creates one target per service instance using the service address and port from Consul's health check data.

Can I discover services from multiple Consul datacenters?

Yes, configure multiple consul_sd_configs entries — one per datacenter. Each entry specifies a server and datacenter. Prometheus queries each datacenter independently and merges the results.

What Consul metadata does Prometheus expose?

Prometheus exposes Consul metadata as __meta_consul_* labels: __meta_consul_service, __meta_consul_service_id, __meta_consul_service_address, __meta_consul_service_port, __meta_consul_dc, __meta_consul_tags, __meta_consul_health, and __meta_consul_service_metadata_*.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro