How to monitor Celery
Monitor Celery by checking that the expected number of workers answer celery inspect ping, that queue length in the broker stays below a limit, that periodic tasks from celery beat actually complete (a heartbeat per important task), and that task exceptions reach an error tracker. Vigil covers each with agent commands, heartbeats and a Sentry-compatible endpoint.
What can go wrong with Celery
- Workers alive but stuck. A task blocks on a network call with no timeout and the worker's slots stay busy. Processes look fine; the queue grows.
- Queue backlog. Producers outpace workers after a traffic spike or a slow dependency. Users wait minutes for emails, exports or payments to process.
- celery beat not running, or running twice. No beat means no periodic tasks at all, with no error. Two beats means every periodic task runs twice.
- Errors swallowed. A task that raises is logged on the worker and retried or dropped; unless something collects the exception, nobody sees it.
- Redis visibility timeout. With the Redis broker, a task not acknowledged within
visibility_timeout(1 hour by default) is delivered again, so long tasks withacks_latecan run twice.
The signals that matter, with alert thresholds
| Signal | Alert when | Why it matters |
|---|---|---|
| Workers answering ping | fewer than you run | Capacity lost. |
| Queue length per queue | > a few minutes' worth of work | Backlog building. |
| Periodic task success ping | late | beat or the task is broken. |
| Task exceptions | new error type, or a spike | Bugs and failing dependencies. |
| Worker memory | growing without bound | Leak; set --max-tasks-per-child. |
Thresholds are starting points. Tune them after a week of data: an alert nobody acts on should be raised or removed.
How to check Celery by hand
celery -A proj inspect ping celery -A proj inspect active
celery -A proj inspect reserved
redis-cli -n 0 llen celery
sudo rabbitmqctl list_queues name messages consumers
systemctl status celerybeat # or: pgrep -af 'celery.*beat'
How to watch Celery with Vigil
- Add the host under Servers and run the one-line installer it shows (
curl -fsSL https://puzaricloud.in/install-server-agent.sh | sh -s -- --token <token>). The agent is one Python file with no dependencies; CPU, memory, disk, inode and load rules start working with the first report. Add the worker service and beat to the systemd services to watch. - Add the commands below: missing workers (limit
celery_workers_missing = 1) and queue length (limit e.g.celery_queue = 500). Commands run every interval with a 10-second timeout. - For each periodic task that matters, create a Heartbeat in New monitor with the beat schedule, and call the ping URL (e.g. with httpx) at the end of the task. If beat stops, the pings stop.
- Create a project under Errors and use its DSN with
sentry_sdk.init(dsn=…); the Sentry SDK enables its Celery integration automatically, so task exceptions arrive grouped with arguments and breadcrumbs. - For task traces, use
opentelemetry-instrumentation-celeryand send spans to the OTLP endpoint (quick start).
{
"commands": {
"celery_workers_missing": "cd /srv/app && echo $(( 4 - $(.venv/bin/celery -A proj inspect ping 2>/dev/null | grep -c pong) ))",
"celery_queue": "redis-cli -n 0 llen celery"
}
}
Every alert goes to the channels you pick: email, Slack, Telegram, Discord, Microsoft Teams, Pushover, webhooks or on-call paging. Failures are confirmed by a second check before anyone is woken up.
Celery monitoring FAQ
Why not use Flower?
Flower is good for looking at workers and tasks interactively. It does not page anyone when a worker vanishes or a queue grows, which is what the commands and heartbeats here are for. Use both if you like Flower's UI.
What queue length should alert?
Think in time: queue length divided by throughput. If workers finish 50 tasks a minute and users should wait at most 5 minutes, alert at 250.
How do I stop memory leaks in workers?
Set --max-tasks-per-child (or worker_max_tasks_per_child) so each process is replaced after N tasks, and watch memory on the server to confirm it levels off.