Django-RQ Monitoring
Monitoring and management of Django-RQ in django-cfg: the Django admin, Prometheus metrics, CLI tools and the Python API.
Monitoring Overview
Django-cfg provides multiple ways to monitor Django-RQ:
| Method | Use Case | Real-time | Production |
|---|---|---|---|
| Django Admin | Manual monitoring and management | ✅ Yes | ✅ Yes |
Python API / rq_cron_status --json | Programmatic access, dashboards | ✅ Yes | ✅ Yes |
| Prometheus | Metrics and alerting | ✅ Yes | ✅ Yes |
| CLI Commands | Quick checks, debugging | ✅ Yes | ⚠️ Limited |
| Web Dashboard | Visual monitoring (django-rq) | ✅ Yes | ✅ Yes |
Django Admin Interface
Access
Navigate to /admin/django_rq/ in your Django admin:
http://localhost:8000/admin/django_rq/Features
Queue Management:
- View all queues and their job counts
- See queue statistics (queued, started, finished, failed)
- Empty queues
- Clear finished/failed jobs
Job Management:
- Browse all jobs with filtering
- View job details (status, args, result, error)
- Cancel running jobs
- Requeue failed jobs
- Delete jobs
Worker Monitoring:
- See active workers
- Check worker status and health
- View worker statistics
Configuration
Enable admin link in config:
django_rq: DjangoRQConfig = DjangoRQConfig(
enabled=True,
redis_db=0, # Required: unique per project
show_admin_link=True, # Show link in admin
)Programmatic access
django-cfg has no RQ REST API (there is no /api/cfg/rq/... route). For a dashboard or a check, use:
python manage.py rq_cron_status --jsonfor the cron heartbeat, per-queue wait and busy workers (below);- the Modules tab of the admin Overview, which shows RQ queues, depth and the
rqcronheartbeat (see Admin Overview); - the
django_rqPython API in your own view or task:
import django_rq
queue = django_rq.get_queue("default")
print(queue.count, len(queue.failed_job_registry))To stop a running job cooperatively, see Job Cancellation.
Prometheus Metrics
Enable Metrics
django_rq: DjangoRQConfig = DjangoRQConfig(
enabled=True,
redis_db=0, # Required: unique per project
prometheus_enabled=True,
)Access Metrics
http://localhost:8000/django-rq/metrics/Available Metrics
# Job counts by queue and status
rq_jobs_total{queue="default",status="finished"} 12450
rq_jobs_total{queue="default",status="failed"} 125
# Current queue length
rq_queue_length{queue="default"} 42
# Worker counts
rq_workers_total{queue="default"} 2
# Job duration
rq_job_duration_seconds{queue="default"} 1.5Prometheus Configuration
# prometheus.yml
scrape_configs:
- job_name: 'django-rq'
static_configs:
- targets: ['localhost:8000']
metrics_path: '/django-rq/metrics/'Grafana Dashboard
Example queries for Grafana:
# Jobs per minute
rate(rq_jobs_total[1m])
# Failed jobs percentage
rate(rq_jobs_total{status="failed"}[5m]) / rate(rq_jobs_total[5m]) * 100
# Queue depth
rq_queue_length
# Average job duration
rate(rq_job_duration_seconds_sum[5m]) / rate(rq_job_duration_seconds_count[5m])CLI Commands
rq_cron_status
Tells a dead rqcron (cron_dead: no heartbeat within --max-heartbeat-age, default 120 s) from a busy worker (starved: a queued job waited longer than --max-wait, default 120 s), with per-queue wait age, the leading rqcron and the job each busy worker runs; exits 1 when not ok. Run it by hand or from monitoring: it boots Django (10-30 s on a busy host), so it is not the container healthcheck. The rqcron healthcheck reads the alive file /tmp/rqcron.alive instead. See Scheduler and Workers.
python manage.py rq_cron_status --queue high --max-wait 60
python manage.py rq_cron_status --json
# {"verdict", "cron_alive", "heartbeat_age_sec", "leader", "queues", "busy", "reason"}rqstats
View queue statistics:
# Basic stats
python manage.py rqstats
# Real-time monitoring (refresh every 1 second)
python manage.py rqstats --interval 1
# Specific queue
python manage.py rqstats --queue defaultOutput:
default |██████████████████ | 42 0 0
high |█ | 1 0 0
low | | 0 0 0
queued: 43 workers: 3Worker Management
# Start single worker
python manage.py rqworker default
# Start worker pool (4 workers)
python manage.py rqworker-pool default --num-workers 4
# Start worker for multiple queues (priority)
python manage.py rqworker high default low
# Start with verbose logging
python manage.py rqworker default --verboseScheduler Management
# Start the cron scheduler (one per project)
python manage.py rqcron
# Print the registered schedules (and not_registered entries) as JSON
python manage.py rqcron --list
# Cron scheduler with debug logging
python manage.py rqcron -l DEBUGWeb Dashboard
Django-RQ includes built-in web dashboard:
http://localhost:8000/django-rq/Features
- Queues Overview: See all queues at a glance
- Job Browser: Browse and filter jobs
- Worker Status: Monitor active workers
- Statistics: Charts and graphs
- Actions: Cancel, requeue, delete jobs
Monitoring Best Practices
1. Set Up Alerting
# Monitor queue depth
if queue.count > 1000:
send_alert("Queue depth too high")
# Monitor failed jobs
failed_rate = failed_jobs / total_jobs
if failed_rate > 0.1: # 10%
send_alert("High failure rate")
# Monitor worker health
if active_workers == 0:
send_alert("No active workers")2. Track Key Metrics
- Queue depth: Number of pending jobs
- Processing rate: Jobs per second
- Failure rate: Failed jobs percentage
- Average duration: Job execution time
- Worker count: Active workers
3. Monitor Redis Health
# Check Redis memory usage
redis-cli info memory
# Check Redis keyspace
redis-cli info keyspace
# Monitor Redis connections
redis-cli info clients4. Use Logging
import logging
logger = logging.getLogger('rq.jobs')
def my_task():
logger.info("Task started")
# ...
logger.info("Task completed")5. Implement Health Checks
def health_check_task():
"""Periodic health check task."""
import django_rq
# Check queues
for queue_name in ['default', 'high', 'low']:
queue = django_rq.get_queue(queue_name)
# Check queue depth
if queue.count > 1000:
logger.warning(f"Queue {queue_name} depth: {queue.count}")
# Check failed jobs
failed_count = len(queue.failed_job_registry)
if failed_count > 100:
logger.warning(f"Queue {queue_name} failed jobs: {failed_count}")
# Check workers
workers = django_rq.get_workers()
if len(workers) == 0:
logger.error("No active workers!")
return {"healthy": True, "queues": len(queues), "workers": len(workers)}
# Schedule health check
RQScheduleConfig(
func="apps.monitoring.tasks.health_check_task",
interval=60, # Every minute
queue="high",
)Troubleshooting
Issue: Jobs Not Processing
Check:
- Are workers running?
ps aux | grep rqworker - Is Redis running?
redis-cli ping - Check worker logs
- Check queue:
python manage.py rqstats
Solution:
# Start workers
python manage.py rqworker defaultIssue: High Memory Usage
Check:
- Redis memory:
redis-cli info memory - Worker memory:
ps aux | grep rqworker
Solution:
# Set result TTL to expire old results
RQQueueConfig(
queue="default",
default_result_ttl=500, # 8 minutes
)Issue: Failed Jobs Accumulating
Check: the failed registry of the queue in the django-rq admin pages, or:
import django_rq
registry = django_rq.get_queue("default").failed_job_registry
print(len(registry))Solution: requeue or delete the jobs from the django-rq admin, or in a shell:
for job_id in registry.get_job_ids():
registry.requeue(job_id)See Also
Documentation
- Overview - Introduction
- Configuration - Setup
- Examples - Code examples
- Job Cancellation - Cooperative cancellation for long-running jobs
- Architecture - Design
Tools
- Django-RQ Dashboard - Built-in dashboard
- RQ Dashboard - Standalone dashboard
- Prometheus - Metrics platform
- Grafana - Visualization