cloudflared
cloudflared copied to clipboard
💡Get the connection id of a particular running instance
Describe the feature you'd like A way to get the connection id of a particular instance that is running on a system after it has been run.
Describe alternatives you've considered I am aware of how to get the list of connections for a particular tunnel by querying the API or using the info command. But, I can’t figure out which system a particular connection refers to.
One way could be to check the logs when a connection starts but since I am looking for an automatic way to figure this out, parsing log files seems to be a very brittle way. Moreover, using the origin IP is not possible when multiple instances are running in the same cluster as they will all give the same origin IP.
I also noticed that I could create tags while creating a tunnel but not while running them. Else, that would have been a sure shot way to identify the connections.
Additional context I was considering submitting a PR for this but whatever way is considered, it needs to be stored by cloudflare so that it is accessible by other systems. This might mean a change in the cloudflare tunnel backend which might not be feasible by the maintainers. Is there any other way this can be done? Related community discussion: https://community.cloudflare.com/t/get-the-connection-id-of-a-particular-running-instance/396113
You mention "connection id" but then you refer "a running instance". So I think you actually mean "connectorId", right?
To clarify: when you run cloudflared tunnel, it executes 1 process (i.e., 1 connector, with an associated random ID that is ephemeral to this process), which then establishes 4 outbound long-lived connections to Cloudflare Global Network (each one with a random ID) that can be rotated over time during the lifetime of this 1 process/connector.
Assuming you mean the connector id, then you can obtain it from the /ready endpoint of your cloudflared instance's metrics port.
I.e., when you run the tunnel, you can pass a flag (or config parameter) to define the metrics port: cloudflared tunnel --hello-world --metrics :12345
You can then query it:
curl -s 127.0.0.1:12345/ready | jq
{
"status": 200,
"readyConnections": 3,
"connectorId": "1c0b85d1-119a-4610-9c90-6208f58ef941"
}
This is pretty much what I was looking for! This is far better than parsing logs and yes, I get mixed up with the connectorid/connectionid terminology. Thanks for the response.
Still, do you think there is an opportunity to have tags for each "connector"? I was looking at the source code and there is a point when a structure has Tags as a property but that doesn't seem to do anything.
https://github.com/cloudflare/cloudflared/blob/d2cb80333652cb24f7d128e81485a195a300f2ad/cmd/cloudflared/tunnel/configuration.go#L333-L358
Yes, that request for "tags" associated with a connector makes sense.
We almost did that some time ago in the scope of some related work. I'll let @abelinkinbio track the request.
Let’s keep this open to track this request.
Hi
I have this request too. I have multiple instances running on devices on our LAN (for redundancy) - but no way of knowing which instance is running on which server.
While I think this is a good idea, I would rather have the option of passing a variable 'name' to the cloudflared instance, eg '-name tunnel1' Then being able to see that 'name' field in the connectors page.