API, WebSocket and server performance monitoring for Django, with a built-in admin dashboard and PDF reports.
Project description
django-perfy
API, WebSocket and server performance monitoring for Django — with a built-in admin dashboard, PDF reports, and the option to keep all telemetry in a separate database.
django-perfy captures request latency, database query counts, WebSocket
events and host resource usage (CPU / memory / Redis / Postgres), rolls them up
into summaries, and surfaces everything through a dashboard and downloadable PDF
reports.
Links
- 📖 Documentation: https://rohith-baggam.github.io/django-perfy/
- 💻 Source code (GitHub): https://github.com/rohith-baggam/django-perfy/
- 🐛 Issues: https://github.com/rohith-baggam/django-perfy/issues
- 📦 PyPI: https://pypi.org/project/django-perfy/
Features
- API monitoring — a middleware records endpoint, method, status, response time, DB query count and DB time, with configurable sampling.
- WebSocket monitoring — a Channels consumer mixin records connect / disconnect / send / receive events and timings.
- Resource snapshots — periodic CPU, memory, Redis and Postgres metrics via Celery tasks and a self-contained background timer (works without Celery Beat).
- Rollups — minute/hour
PerformanceSummaryaggregates for fast dashboards. - Dashboard — a staff-only Jinja2 dashboard (overview, API, WebSocket, resources, DB queries, correlation, raw logs).
- PDF reports — latency, throughput, bottlenecks and resource-utilization reports, previewable in-browser, downloadable, or emailable.
- Secondary database — point all telemetry at a separate DB alias with one setting; the bundled router handles reads, writes and migrations.
Requirements
- Python 3.10+
- Django 4.2+
- Celery 5.2+, Redis, psutil (installed automatically)
jinja2+weasyprintfor the dashboard and PDF reports (thereportsextra). WeasyPrint needs system libraries (Pango, Cairo) — see its install docs.
Installation
pip install django-perfy # core
pip install "django-perfy[reports]" # + dashboard & PDF reports
Quickstart
# settings.py
INSTALLED_APPS = [
# ...
"django_perfy",
]
MIDDLEWARE = [
# ... after AuthenticationMiddleware so request.user is available ...
"django_perfy.middleware.PerformanceMiddleware",
]
python manage.py migrate
Instrument WebSocket consumers (optional):
from channels.generic.websocket import AsyncWebsocketConsumer
from django_perfy.mixins import WebSocketLoggingMixin
class ChatConsumer(WebSocketLoggingMixin, AsyncWebsocketConsumer):
...
Full install steps — extras, WeasyPrint system libraries, the dashboard's Jinja2 backend and static files, and the secondary-database migration — are in the documentation.
Configuration
All configuration lives in a single PERFORMANCE_MONITOR dict. Any key you omit
falls back to its default, and Django's system-check framework validates the
block on manage.py check.
PERFORMANCE_MONITOR = {
"ENABLED": True,
"SAMPLING_RATE": 0.1, # sample 10% of normal requests
"SLOW_REQUEST_THRESHOLD_MS": 500, # always capture requests slower than this
"EXCLUDED_PATHS": ["/health/", "/metrics/", "/favicon.ico"],
"RETENTION_DAYS_RAW": 30,
"RETENTION_DAYS_RESOURCES": 90,
"QUEUE_NAME": "performance_logs",
"USER_ID_SALT": "change-me", # salts hashed user ids
"SERVICES": [],
# Off by default: headers/bodies routinely carry session cookies/auth
# tokens/PII. See the settings reference for the full redaction options.
"CAPTURE_HEADERS": False,
"REDACTED_HEADERS": ["authorization", "cookie", "set-cookie", "x-api-key"],
"CAPTURE_BODY": False,
"REDACTED_BODY_FIELDS": ["password", "token", "secret", "card_number"],
# Store telemetry in the default DB, or point at a secondary alias:
"DATABASE": "default",
}
CAPTURE_HEADERSandCAPTURE_BODYdefault toFalsebecause headers and bodies routinely carry session cookies, auth tokens and other PII. Leave both off until you've reviewedREDACTED_HEADERSandREDACTED_BODY_FIELDS— turning them on isn't a casual flip.
Every key, its type, default and description is in the settings reference, and the parts that need more explanation are covered under Configuration.
Documentation
| Topic | Link |
|---|---|
| Why django-perfy (vs Prometheus/Grafana) | https://rohith-baggam.github.io/django-perfy/why-django-perfy/ |
| Getting started | https://rohith-baggam.github.io/django-perfy/getting-started/ |
| Configuration | https://rohith-baggam.github.io/django-perfy/configuration/ |
| Dashboard & reports | https://rohith-baggam.github.io/django-perfy/features/dashboard-and-reports/ |
| Secondary database | https://rohith-baggam.github.io/django-perfy/guides/secondary-database/ |
| Emailing reports | https://rohith-baggam.github.io/django-perfy/guides/email/ |
| Celery setup | https://rohith-baggam.github.io/django-perfy/guides/celery-setup/ |
| Management commands | https://rohith-baggam.github.io/django-perfy/reference/management-commands/ |
| Intro, demo & installation videos | https://rohith-baggam.github.io/django-perfy/background/ |
Development
python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev,reports]"
pytest
pre-commit install
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_perfy-0.1.0.tar.gz.
File metadata
- Download URL: django_perfy-0.1.0.tar.gz
- Upload date:
- Size: 141.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71ca8e698817e992e780610dc5107ed4ea1546fed81e2f78b6ff1a677394e5d4
|
|
| MD5 |
de44a886ef27dc7f7fffca1e880959ed
|
|
| BLAKE2b-256 |
6dc9fe705538f4ad61de923b672dcabf68cf4f2344ba8173e7be6aa05e87ca27
|
File details
Details for the file django_perfy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_perfy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 120.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f19ffad91714123fa8858fbb6e56019ce594b37731ac6c75a1c13b87a7980b8b
|
|
| MD5 |
68f201ba4013d1ab1dc2f4d6a588b27b
|
|
| BLAKE2b-256 |
245a353f0339dcc786f34ad2ebad662a6371e493f7f9e6b8d524edc97ca90d05
|