-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
A simple django middleware that logs request times using the Django 1.3 logging support, and a management command to analyze the resulting data. Once installed and configured you can run a command line these: | ||
|
||
<pre>python manage.py analyze_timelog | ||
python manage.py analyze_timelog --noreverse</pre> | ||
|
||
And generate useful tabular data like this: | ||
|
||
<pre> | ||
+--------------------------+--------+--------+-------+---------+---------+-------+-----------------+ | ||
| view | method | status | count | minimum | maximum | mean | stdev | | ||
+--------------------------+--------+--------+-------+---------+---------+-------+-----------------+ | ||
| boxes.viewsBoxDetailView | GET | 200 | 9430 | 0.14 | 0.28 | 0.21 | 0.0700037118541 | | ||
+--------------------------+--------+--------+-------+---------+---------+-------+-----------------+ | ||
| boxes.viewsBoxListView | GET | 200 | 66010 | 0.17 | 0.28 | 0.232 | 0.0455415351076 | | ||
+--------------------------+--------+--------+-------+---------+---------+-------+-----------------+ | ||
| django.views.staticserve | GET | 200 | 61295 | 0.00 | 0.02 | 0.007 | 0.0060574669888 | | ||
+--------------------------+--------+--------+-------+---------+---------+-------+-----------------+ | ||
</pre> | ||
|
||
This project was heavily influenced by the Rails "Request log analyzer":https://github.com/wvanbergen/request-log-analyzer. | ||
|
||
h2. Installation | ||
|
||
<pre>pip install django-timelog</pre> | ||
|
||
Once installed you need to do a little configuration to get things working. First add the middleware to your MIDDLEWARE_CLASSES in your settings file. | ||
|
||
<pre>MIDDLEWARE_CLASSES = ( | ||
'timelog.middleware.TimeLogMiddleware',</pre> | ||
|
||
Next add timelog to your INSTALLED_APPS list. This is purely for the management command discovery. | ||
|
||
<pre>INSTALLED_APPS = ( | ||
'timelog',</pre> | ||
|
||
Then configure the logger you want to use. This really depends on what you want to do, the django 1.3 logging setup is pretty powerful. Here’s how I’ve got logging setup as an example: | ||
|
||
<pre>TIMELOG_LOG = '/path/to/logs/timelog.log' | ||
|
||
LOGGING = { | ||
'version': 1, | ||
'formatters': { | ||
'plain': { | ||
'format': '%(asctime)s %(message)s'}, | ||
}, | ||
'handlers': { | ||
'timelog': { | ||
'level': 'DEBUG', | ||
'class': 'logging.handlers.RotatingFileHandler', | ||
'filename': TIMELOG_LOG, | ||
'maxBytes': 1024 * 1024 * 5, # 5 MB | ||
'backupCount': 5, | ||
'formatter': 'plain', | ||
}, | ||
}, | ||
'loggers': { | ||
'timelog.middleware': { | ||
'handlers': ['timelog'], | ||
'level': 'DEBUG', | ||
'propogate': False, | ||
} | ||
} | ||
}</pre> | ||
|