How to view all machines for a service?

I’m building an application where nodes can coordinate amongst each other. What is the most straightforward way to view a list of the sibling machines?

I see there is an answer here which uses a /machines api endpoint.

Is this available somewhere else? For example, an environment variable or a URL which does not require a fly api token?

I think of the Hetzner metadata URL as a model.

Ideally, I’d even be able to do this without any fly-specific code, but don’t mind special-casing a check for whether the code is being run via Fly. If I could transparently check for, say, FLY_MACHINE_NAME and based on that query localhost:1337/application/metadata then that would allow me to implement this without additional configuration.

I think you mean from within the Fly Machine environment, right? Or from the CLI?

If the former, I think you might want to take a look at the txt options in the .internal DNS.

From the fly machine environment, correct. The DNS option is exactly what I was looking for, thank you! Can I assume that it is fairly realtime and up to date? Are machines that are no longer “live” (for example, old deployments, machines pending delete, machines no longer in LB) excluded?

Yes and yes.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.