django-live-dashboard
django-live-dashboard copied to clipboard
Shows current requests to a Django application. Inspired by Phoenix's LiveDashboard.
django_live_dashboard
Inspired by Phoenix's LiveView Dashboard. Uses redis
pub-sub, chart.js, alpine.js, and websockets for streaming realtime updates of all current requests to a Django application.
Requires
- Python 3.6+
- Django 3.0+
- Django to be run via
ASGI
for websockets support
Install
-
pip install django-live-dashboard
orpoetry add django-live-dashboard
- Update current
asgi.py
or use theasgi.py
file in the repo as an example - Add
"django_live_dashboard",
toINSTALLED_APPS
in settings file - Add
"django_live_dashboard.middleware.DjangoLiveDashboardMiddleware",
to beginning of theMIDDLEWARE
list in settings file - Add
DJANGO_LIVE_DASHBOARD
configuration to settings file (see details below) - Add to default
urls.py
:path("admin/", include(django_live_dashboard_urls))
- Run your server with something like
uvicorn project.asgi:application --port=8000
Settings
Configuration is in a DJANGO_LIVE_DASHBOARD
setting.
Example
DJANGO_LIVE_DASHBOARD = {
"ENABLED": True,
"WEBSOCKET_HOST": 'localhost:8000',
"TOTAL_TIME_CUTOFF": 0.5,
"REDIS": {
"HOST": "localhost",
"PORT": 6379,
"DB": 0,
"PUBSUB_CHANNEL": "django_live_dashboard:stats"
},
"CHART": {
"REFRESH": 1000,
"DELAY": 1000,
"DURATION": 100000,
}
}
ENABLED
Whether any statistics should be logged. Defaults to DEBUG
.
WEBSOCKET_HOST
The host that the websocket should listen to. Defaults to localhost
.
TOTAL_TIME_CUTOFF
How long a request should take in seconds before getting logged. For example, if the value is 0.75, any request that takes longer than three quarters of a second will get graphed. Defaults to 0.5
.
REDIS
Redis configuration with standard HOST
, PORT
, and DB
settings in a dictionary.
HOST
The host of the redis server. Defaults to localhost
.
PORT
THe port of the redis server. Defaults to 6379
.
DB
The database of the redis server. Defaults to 0
.
CHART
Configuration for the streaming chart.js
plugin.
DELAY
Delay in milliseconds of the chart.js
which helps to make the drawing more fluid and smooth. Defaults to 1000.
DURATION
Time duration in milliseconds of how much data should be charted. Defaults to 100000.
REFRESH
How often the chart should try to refresh its data. Defaults to 1000.
Example Django project
Found in the example_project
directory in this repo.
How to run
-
redis-server
-
poetry install
-
poetry run example_project/manage.py migrate
-
poetry run example_project/manage.py createsuperuser
-
poetry run uvicorn example_project.project.asgi:application
- Go to http://localhost:8000/monitoring/
- Open up http://localhost:8000/admin/ in a new tab; go back to the first tab and you should see some updated information