Monitoring
Monitoring is a Django 1.9 app which adds logging and a dashboard to a Django project.
Features
- Log model which any application can use.
- Dashboard view and page which shows version information and recent log entries.
- check_mysql_structure command which compares model definitions to equivalent mysql tables and reports any discrepancies. Useful for checking that live database structures are correct.
Quick start
-
Add "monitoring" to your
INSTALLED_APPSsettings. -
Include the monitoring URLconf in your project urls.py like this:
url(r'^monitoring/', include('monitoring.urls', namespace='monitoring')), -
Run
python manage.py syncdbto create the monitoring models. -
Run
python manage.py collectstaticto copy static files to your project's static root. -
Identfy Django project root directory path in settings like this:
from os.path import abspath, dirname DJANGO_ROOT = dirname(dirname(abspath(__file__)))
-
Start the development server and visit /monitoring/dashboard/ to see summary information about the state of the project.
-
Add model-based logging for [appname] to settings.py with:
LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'db_log': { 'level': 'INFO', # Reference to handler in log.py below 'class': 'monitoring.log.DbLogHandler', } }, 'loggers': { '[appname]': { 'handlers': ['db_log', ], 'level': 'INFO', 'propagate': True, }, } } -
Use logging in [appname] like this:
import logging logger = logging.getLogger('[appname]') . . . logger.info('informational message text') logger.warning('warning message text') logger.error('error message text')