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
- https://github.com/PrefectHQ/prefect/blob/master/src/prefect/agent/agent.py#L446-L457
- https://github.com/PrefectHQ/prefect/blob/master/src/prefect/agent/agent.py#L147
- https://github.com/PrefectHQ/prefect/blob/master/src/prefect/config.toml#L90-L91
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
}
}