How can I programmatically check whether Prefect agent is healthy?

User question

is there some sort of API endpoint that we can hit which serves as a health check? I’m wondering how I can programmatically check that the agent is healthy

Answer

Yep! The agent hosts a health check API as hown in the links below

The agent address needs to be configured via:

  • the config (prefect.cloud.agent.agent_address)
  • or CLI (--agent-address).

Once configured, the agent will host an API with a GET route /api/health that will respond with an empty JSON blob if healthy.

You may also send a GET request to /api/poke to tell the agent to look for scheduled flow runs immediately instead of respecting the normal sleep interval.

Example:

prefect agent local start --agent-address http://0.0.0.0:5000/

The request below returns an empty dictionary:

curl http://localhost:5000/api/health

Or you can hit the server API to get a last queried time

https://cloud.prefect.io/api?query={%0Aagent{%0A%20 id%0A%20 last_queried%0A}}

{
  agent {
    id
    last_queried
  }
}

Source: How can I programmatically check whether Prefect agent is healthy? · Issue #5400 · PrefectHQ/prefect · GitHub