Skip to content

feat: support multiple metrics addresses via repeated flag#1601

Open
IngmarStein wants to merge 1 commit intocloudflare:masterfrom
IngmarStein:multiple_metrics_endpoints
Open

feat: support multiple metrics addresses via repeated flag#1601
IngmarStein wants to merge 1 commit intocloudflare:masterfrom
IngmarStein:multiple_metrics_endpoints

Conversation

@IngmarStein
Copy link

Summary

This PR updates the --metrics flag to accept multiple values, allowing the metrics server to bind to specific addresses (e.g., localhost IPv4 and IPv6) without exposing the endpoint to all interfaces via [::].

Changes

  • CLI: Changed metrics flag to StringSliceFlag. Users can now pass --metrics multiple times.
  • Metrics Package:
    • CreateMetricsListener now accepts a slice of addresses and returns a slice of listeners.
    • ServeMetrics now accepts a slice of listeners and serves them concurrently using a shared http.Server.
  • Tunnel Command:
    • StartServer updated to initialize and close multiple listeners.
    • readyCommand updated to check the first configured metrics address.
  • Tests: Added test cases for multiple listener creation.

How to test

Run the tunnel with multiple metrics flags:

cloudflared tunnel run --metrics 127.0.0.1:2020 --metrics [::1]:2020 ...

Verify that the metrics endpoint is accessible on both addresses but not on external interfaces.

@jcsf
Copy link
Contributor

jcsf commented Mar 3, 2026

Hi,
What is the problem you are trying to resolve here? Why is more than 1 metrics address needed? Can you give us an example or a more detailed explanation?

@IngmarStein
Copy link
Author

@jcsf if I use "--metrics 127.0.0.1:2020", cloudflared only listens on IPv4 (at least on macOS 26) and with "--metrics [::1]:2020", it listens on IPv6 only. I'd like to make the metrics endpoint available on both stacks, but without opening it up beyond localhost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants