Add domain to caddy_http_requests_total metrics data?

For the caddy admin API you can see which path was called and how often in the metrics data:
caddy_admin_http_requests_total{code=“200”,handler=“metrics”,method=“GET”,path="/metrics"}

I was wondering if there was a way to do something similar but for domain on caddy_http_requests_total data. Something like this?

caddy_http_requests_total{domain=“example.com”,handler=“reverse_proxy”,server=“srv0”} 1219
caddy_http_requests_total{domain=“otherdomain.com”,handler=“reverse_proxy”,server=“srv0”} 123

The rationale being we are hosting many domains off one caddy instance and I’m curious to know who’s sending how many requests. It’s not really important to know too much other than that.

Alternatively I suppose this is something I could log? I was looking through the log docs but I wasn’t exactly sure how to create a custom log format that writes the origin/domain out? I did some googling but couldn’t find an example, if you had one handy I would be much obliged!

This one’s for you, @hairyhenderson :slight_smile:

The access logs emit almost everything about the request. You can see a sample here: How Logging Works — Caddy Documentation

The domain name is in the request>host field.

Unfortunately the metrics issue looks to be impossible at the moment:

Hey thanks guys for your amazingly quick replies!

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