Caddy V2 and prometheus metrics

1. Caddy version (caddy version):

v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=

2. How I run Caddy:

I run Caddy in docker with docker-compose with static configuration

a. System environment:


b. Command:

CMD ["/usr/bin/caddy", "run", "--config", "/etc/Caddyfile"]

d. My complete Caddyfile or JSON config:

    admin {
    	metrics /metrics

3. The problem I’m having:

As per docs I’m trying to scrape metrics but 404 is returned.

(running inside container)

/srv #  curl -v localhost:2019/metrics
*   Trying
* Connected to localhost ( port 2019 (#0)
> GET /metrics HTTP/1.1
> Host: localhost:2019
> User-Agent: curl/7.69.1
> Accept: */*
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
< Date: Sun, 06 Dec 2020 10:39:17 GMT
< Content-Length: 19
404 page not found
* Connection #0 to host localhost left intact

4. Error messages and/or full log output:

{"level":"info","ts":1607251157.8994603,"logger":"admin.api","msg":"received request","method":"GET","host":"localhost:2019","uri":"/metrics","remote_addr":"","headers":{"Accept":["*/*"],"User-Agent":["curl/7.69.1"]}}

5. What I already tried:

Reconfigure, tried to debug with curl and logs

Any help or suggestions will be highly appreciated
Thanks for supporting this great product

Apparently, configuration format of Caddyfile has changed again and after update to 2.2.1 server didn’t start because of the metrics is not valid parameter anymore.

I have removed it and viola, metrics became available at localhost:2019/metrics

So update to 2.2.1 resolved this issue.

Metrics was a feature introduced in v2.2, it did not exist in v2.1

FYI that global options syntax is not correct, the admin global options don’t take handler directives as arguments. Metrics are always-on and accessible from the admin API at /metrics. See the global options docs for the options available to admin:

There is a metrics directive, for site blocks, that allows you to make the metrics endpoint available outside of the admin API, on whatever server you want:

1 Like

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