How to access metrics from another host?

1. Caddy version (caddy version):

v2.3.0 h1:fnrqJLa3G5vfxcxmOH/+kJOcunPLhSBnjgIvjXV/QTA=

2. How I run Caddy:

a. System environment:

Ubuntu 20.04
Docker 19.03.1

b. Command:

docker-compose up -d caddy2

c. Service/unit/compose file:

version: '3.7'
services:
  caddy2:
    image: gotson/caddy-cloudflare:latest
    container_name: caddy2
    volumes:
      - ~/opt/appdata/caddy2/Caddyfile:/etc/caddy/Caddyfile
      - ~/opt/appdata/caddy2/data:/data
      - ~/opt/appdata/caddy2/config:/config
      # - ~/opt/appdata/caddy2/glype:/srv
    ports:
      - 2018:2018
      - 2019:2019
      - 80:80
      - 443:443
    environment:
      - CLOUDFLARE_API_TOKEN=${CLOUDFLARE_API_TOKEN}
    restart: unless-stopped

d. My complete Caddyfile or JSON config:

http://0.0.0.0:2018 {
  metrics
}

3. The problem I’m having:

I am trying to access the Prometheus metrics from outside the container, but can’t.

Without the added metrics block in my Caddyfile, i tried this without success:

curl localhost:2019/metrics
curl: (56) Recv failure: Connection reset by peer

I try to exposed the metrics as its own domain, listening to 0.0.0.0:2018, but that returns nothing:

curl localhost:2018
curl localhost:2018/metrics

4. Error messages and/or full log output:

nothing relevant even with debug

5. What I already tried:

6. Links to relevant resources:

OK, i’ve found how to listen to all interfaces instead of just localhost for the admin API.

I added this global config to my Caddyfile:

{
  admin 0.0.0.0:2019
}

Hmm, try with this:

:2018 {
  metrics
}

The difference is that Caddy seems to make a host matcher for 0.0.0.0 otherwise. Seems incorrect. Omitting that won’t use a host matcher but will listen on all interfaces. Seems like a bug. Looking into it.

You can see what I mean by adapting your Caddyfile with caddy adapt --pretty --config /path/to/Caddyfile

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