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”]}
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:
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.