caddy-docker-proxy icon indicating copy to clipboard operation
caddy-docker-proxy copied to clipboard

Any way to get metrics on 2019 port?

Open andreevgrisha opened this issue 1 year ago • 8 comments

inside caddy-proxy container config/caddy/autosave.json show {"admin":{"listen":"tcp/localhost:2019"} but with exposed 2019 port on docker-compose file, i can't connect to 2019, responce is: Connection reset by peer

need advice - how change this settings to {"admin":{"listen":":2019"}

or any other way to expose hostip:2019/metrics with lucaslorentz/caddy-docker-proxy and docker-compose ?

andreevgrisha avatar May 06 '24 08:05 andreevgrisha

CDP needs control of the admin endpoint because it does managed config reloads.

You can serve metrics from any port with the metrics directive: https://caddyserver.com/docs/caddyfile/directives/metrics

Just add labels to your Caddy container to produce config like this:

:2020 {
    metrics
}

francislavoie avatar May 06 '24 13:05 francislavoie

thanks for answer! can you help with label example of this? have not idea how do it right way... may be or wrong?

labels:
  caddy.handle_path: /metrics
  caddy.handle_path.0_reverse_proxy: {{upstreams 2020}}

andreevgrisha avatar May 06 '24 15:05 andreevgrisha

No, you need to define a site (like if you used a domain) but with :2020 instead. No reverse_proxy.

francislavoie avatar May 06 '24 16:05 francislavoie

clear!

    labels:
      caddy_0:
      caddy_0.servers:
      caddy_0.servers.metrics:
      caddy_1: ":2020"
      caddy_1.metrics: "/metrics"
      caddy_1.metrics.disable_openmetrics:

thank a lot

andreevgrisha avatar May 06 '24 17:05 andreevgrisha

Can we also expose /reverse_proxy/upstreams in similar way?

m0n0chr0me avatar Aug 29 '24 23:08 m0n0chr0me

Unfortunately no @m0n0chr0me. But you could do something silly like this:

:2020 {
	handle /reverse_proxy/upstreams {
		reverse_proxy localhost:2019
	}
	handle {
		# fallback for other paths
	}
}

francislavoie avatar Aug 30 '24 04:08 francislavoie

Thank you @francislavoie. I tried this and I was getting the error {"error":"host not allowed: caddy-docker-proxy:2020"}

So I have checked with chatgpt to find the below solution which is working fine. Thank you for your guidance.

:2020 {
        handle /reverse_proxy/upstreams {
		reverse_proxy localhost:2019 {
                      header_up Host localhost:2019
	}
}

Equivalent labels would be

labels:
  - caddy_1=:2020
  - caddy_1.handle=/reverse_proxy/upstreams
  - caddy_1.handle.reverse_proxy=localhost:2019
  - caddy_1.handle.reverse_proxy.header_up=Host localhost:2019

And also need to expose 2020 in the ports section. Now i can load the caddy widget from Homepage.

m0n0chr0me avatar Aug 30 '24 08:08 m0n0chr0me