Skip to content

Prometheus Scrape Config DNS Resolution Error Fix

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about Prometheus Scrape Config DNS Resolution Error Fix. We cover key concepts, practical examples, and best practices.

Your Prometheus targets show Get "http://localhost:9100/metrics": dial tcp: lookup localhost: no such host — the target address cannot be resolved, the port is included in the host field, or the service discovery returns invalid endpoints.

The Problem

scrape_configs:
  - job_name: 'node'
    static_configs:
      - targets: ['localhost:9100/metrics']

Prometheus expects targets in host:port format. Adding a path (/metrics) to the target address causes DNS lookup to fail — Prometheus tries to resolve localhost:9100/metrics as a hostname.

Step-by-Step Fix

1. Use host:port format for targets

scrape_configs:
  - job_name: 'node'
    static_configs:
      - targets: ['localhost:9100']  # No path — just host:port
    metrics_path: /metrics  # Separate path configuration

2. Configure metrics path separately

scrape_configs:
  - job_name: 'node'
    static_configs:
      - targets: ['localhost:9100']
    metrics_path: /metrics  # Default is /metrics
    scheme: http             # Default is http
    scrape_interval: 15s
    scrape_timeout: 10s

3. Handle DNS failure in service discovery

scrape_configs:
  - job_name: 'kubernetes-nodes'
    kubernetes_sd_configs:
      - role: node
    relabel_configs:
      - source_labels: [__address__]
        regex: '(.*):10250'
        replacement: '${1}:9100'
        target_label: __address__

4. Verify DNS resolution

# Check DNS resolution for the target
nslookup localhost

# Test metric endpoint
curl http://localhost:9100/metrics

# Check Prometheus target status
# http://prometheus:9090/targets

5. Use proper target formatting for different schemes

scrape_configs:
  - job_name: 'api'
    scheme: https
    static_configs:
      - targets: ['api.example.com:443']
    metrics_path: '/api/metrics'
    tls_config:
      insecure_skip_verify: false

Expected output:

Target: localhost:9100
Status: UP
Labels: {instance="localhost:9100", job="node"}
Metrics: 847 metrics collected

Prevention Tips

  • Use host:port format in targets (no path)
  • Configure metrics_path separately
  • Use service discovery instead of static configs for dynamic environments
  • Verify DNS resolution independently before configuring Prometheus
  • Check target status in Prometheus UI after config changes

Common Mistakes with scrape config

  1. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  2. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  3. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks

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

### Can I use URLs in target configuration?

No, Prometheus targets use host:port format only. Use metrics_path for the URL path, scheme for http/https, and params for query parameters. The target address is always host:port.

Why does my target show as DOWN even though the endpoint works?

Check: (1) Prometheus can reach the target (network connectivity), (2) the target returns valid Prometheus metrics format, (3) the scrape_timeout is long enough, (4) TLS configuration matches the target's certificate. Use curl from the Prometheus server to verify.

How do I scrape multiple ports on the same host?

Use multiple jobs or relabeling. For multiple jobs: create one scrape_config per port with different targets. For relabeling: use service discovery labels to set different ports based on service annotations.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro