Caddy metrics with existing Prometheus

1. Caddy version (caddy version):

v2.3.0

2. How I run Caddy:

a. System environment:

CentOS 8

b. Command:

/opt/caddy/caddy run --config="/opt/caddy/caddyfile" --adapter="caddyfile"

c. Service/unit/compose file:

systemd (but not used for caddy)

d. My complete Caddyfile or JSON config:

school.pgroup.com {	
	root * /var/www/school
	file_server
}

3. The problem I’m having:

I already have an existing Prometheus collector in my environment. Which means I would like to use the existing one for collection metrics from caddy. I can’t collect metrics since Caddy seem to not “deliver” (or present) metrics to all origins. Can these origins being modified, so they accept requests from an external machine?

4. Error messages and/or full log output:

In the logs it said:
“admin endpoint started”,“address”:“tcp/localhost:2019”,“enforce_origin”:false,“origins”:[“localhost:2019”,"[::1]:2019",“127.0.0.1:2019”]}

5. What I already tried:

I tried what is mentioned here:

and

6. Links to relevant resources:

Just a quick tip, if you name your config Caddyfile (uppercase C, as is standard), you can omit the --adapter arg.

Yeah - by default Caddy only exposes the admin API to localhost:2019. If your prometheus instance is elsewhere, what you can do is make a site block like this, to collect the metrics instead:

:2020 {
	metrics
}

That’ll make it accessible from any origin, on port 2020.

This approach is preferable over widening the admin API’s accessibility, especially if you don’t plan to use the API, because it reduces risk. You don’t want the wrong people to have access to the API, else they could change your config.

Hey francislavoie,

thank you a lot! That was exactly what I was searching for. Great :slight_smile:
I will test that with the Caddyfile too.

have a great day
pamalosebi

1 Like

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