Skip to Content
FeaturesModulesMonitorConfiguration

Monitor Configuration

django_monitor is configured through CloudflareConfig in django_cf — there is no separate MonitorConfig. Monitor-specific options live on CloudflareConfig:

from django_cfg import CloudflareConfig class MyConfig(DjangoConfig): cloudflare: CloudflareConfig = CloudflareConfig( enabled=True, account_id="${CF_ACCOUNT_ID}", api_token="${CF_API_TOKEN}", d1_database_id="${CF_D1_DATABASE_ID}", # Monitor-relevant options: telegram_alerts_enabled=True, # notify on UNHANDLED_EXCEPTION / RQ_FAILURE / SLOW_QUERY (>5s) )

Unlike the old built-in Monitor app, there is no FrontendMonitorConfig, no monitor_db_alias, and no separate database required. All events go to D1.


Options

telegram_alerts_enabled

Default: False

Sends a Telegram message when a critical server event occurs:

Event typeAlert condition
UNHANDLED_EXCEPTIONevery new occurrence
RQ_FAILUREevery new occurrence
SLOW_QUERYqueries > 5 seconds

Requires TelegramConfig to be configured in DjangoConfig (bot token + chat ID).


Slow Query Threshold

The slow query capture hook fires when a query exceeds a threshold. This threshold is hardcoded at 500 ms in the current version of django_monitor.

Telegram alerts for slow queries fire only at > 5 s.


Retention & Cleanup

D1 storage is not automatically pruned — use the management command:

# Delete resolved server events older than 90 days (default) python manage.py monitor_cleanup # Custom retention python manage.py monitor_cleanup --days 30 # Preview without deleting python manage.py monitor_cleanup --dry-run

Open (unresolved) server events are never deleted, regardless of age or --days value.

Frontend events are also pruned by monitor_cleanup. Schedule it via cron or Django-RQ to run daily.


Schema Initialization

The server_events and frontend_events tables in D1 are created automatically on first use (lazy _ensure_schema()). No manual migration step needed.

To verify the schema is in place:

python manage.py monitor_status

See Also

TAGS: django_monitor, configuration, slow-query, telegram-alerts DEPENDS_ON: [django-monitor/overview]

Last updated on