caddy icon indicating copy to clipboard operation
caddy copied to clipboard

Prometheus Metrics for reverse_proxy upstreams

Open genofire opened this issue 4 years ago • 14 comments

It would be nice to know, which Upstream give which latency, statuscode or health_status.

Maybe it is also nice to enable it per path (related issue #4016).

genofire avatar Apr 30 '21 08:04 genofire

Just duplicated this issue inn https://github.com/caddyserver/caddy/issues/4309 (keep whatever issue you want open :upside_down_face:)

rugk avatar Aug 25 '21 21:08 rugk

Hi @genofire Please check https://grafana.com/grafana/dashboards/14280 With latest caddy and setting up prometheus to /metrics it's already collecting reverse_proxy requests, errors, request/responce time. image Although no status codes.

uniuuu avatar Jul 13 '22 14:07 uniuuu

@uniuuu I think that's just showing how many requests reached the reverse_proxy handler. The question was about metrics for which upstreams were hit, i.e. when you have more than one upstream configured for your reverse_proxy.

francislavoie avatar Jul 13 '22 14:07 francislavoie

Still a much needed feature. Seeing which upstreams are used is a basic information for a loadbalancer and should be included in the metrics.

lfkdev avatar Jul 15 '22 10:07 lfkdev

Might only be partially resolved by #4935, so reopening

mholt avatar Aug 27 '22 18:08 mholt

Hi @uniuuu

Could you please explain how you did the /metrics setup? Because simply turning on the metrics api was not giving me any middleware metrics except the admin metrics.

Please check https://github.com/caddyserver/caddy/issues/4309#issuecomment-1353007832

I request you to help me out with this. Thank you!

farhan-ct avatar Dec 15 '22 19:12 farhan-ct

@farhan-ct you can enable /metrics in the Caddyconfig and you'll see metrics like which endpoints are online and if they're in a healthy state. Example:

[..]
caddy_reverse_proxy_upstreams_healthy{upstream="123.123.123.123:1337"} 1
caddy_reverse_proxy_upstreams_healthy{upstream="123.123.124.123:1338"} 0
caddy_reverse_proxy_upstreams_healthy{upstream="123.123.125.123:1339"} 1
[..]

Make sure you use a new Caddy Version, that feature was just introduced a little while ago. https://caddyserver.com/docs/metrics

lfkdev avatar Dec 15 '22 19:12 lfkdev

@farhan-ct you can enable /metrics in the Caddyconfig and you'll see metrics like which endpoints are online and if they're in a healthy state. Example:

[..]
caddy_reverse_proxy_upstreams_healthy{upstream="123.123.123.123:1337"} 1
caddy_reverse_proxy_upstreams_healthy{upstream="123.123.124.123:1338"} 0
caddy_reverse_proxy_upstreams_healthy{upstream="123.123.125.123:1339"} 1
[..]

Make sure you use a new Caddy Version, that feature was just introduced a little while ago. https://caddyserver.com/docs/metrics

Yes I enabled that and am able to see the metrics that you just mentioned. However, you can find in this link [https://github.com/caddyserver/caddy/issues/4309#issuecomment-1353007832](url) that the @rugk is able to get some other metrics starting with caddy_http_..., request and response stuff. I am struggling on how to get those.

Also, based this PR https://github.com/caddyserver/caddy/pull/3709 You can see the sample code in the introduction that's providing the caddy_http_request* metrics which am unable to find in my v2.6.2 (latest) version

@hairyhenderson

Also, I realised that the metrics I want are available in v2.5.2 image

But as per the doc, enabling the metrics in v2.6.2 should provide these metrics but it doesn't.

farhan-ct avatar Dec 15 '22 19:12 farhan-ct

@farhan-ct please read the 2.6 release notes - metrics need to be explicitly enabled now: https://github.com/caddyserver/caddy/releases/tag/v2.6.0

hairyhenderson avatar Dec 15 '22 20:12 hairyhenderson