Caddy: How to Add Host Labels in Metrics for Prometheus/Grafana?

I have installed Caddy using docker-compose.yml as a reverse proxy.

docker-compose.yml:

version: '3.8'

services:
  caddy:
    container_name: "caddy"
    image: caddy:latest
    restart: unless-stopped
    ports:
      - 80:80
      - 443:443
      - "127.0.0.1:2019:2019"
    volumes:
      - /var/docker/caddy/data:/data
      - /var/docker/caddy/config:/config
      - /var/docker/caddy/Caddyfile:/etc/caddy/Caddyfile
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /var/docker/caddy/logs:/var/log/caddy
    labels:
      - "prometheus.io/scrape=true"
      - "prometheus.io/port=2019"
      - "prometheus.io/metrics_path=/metrics"

Caddyfile:

{
    email ssl@email.com
    admin :2019
    metrics
    log {
        output file /var/log/caddy/access.log
        format json    
        level INFO     
    }
}

domain.com {
    reverse_proxy docker-container:3000
    log
    @metrics_public {
        path /metrics
        not remote_ip private_ranges
    }
    respond @metrics_public 403
}

I want to see only the metrics related to docker-container:3000 in Grafana.
I tried using the following query:

caddy_http_requests_total{host="domain.com"}

but it is not working.

I also tried adding a label to the metrics, but that didn’t work either.

What should I add to make it work correctly? I couldn’t find anything relevant in the documentation.

You need to enable per-host labels

-    metrics
+    metrics {
+          per_host
+    }

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.