|
| 1 | +This is a Django application to make it a bit simpler to use |
| 2 | +Munin (http://munin-monitoring.org/) to monitor various metrics |
| 3 | +for your Django app. |
| 4 | + |
| 5 | +First, it includes a munin plugin that you can symlink into |
| 6 | +/etc/munin/plugins/ and point at your django application and it will |
| 7 | +gather data for munin to graph. Second, it contains a couple views |
| 8 | +that return some very basic information about the state of your app: |
| 9 | +database performance, number of users, number of sessions, etc. Third, |
| 10 | +it provides a decorator to make it simple to expose your own custom |
| 11 | +metrics to Munin. |
| 12 | + |
| 13 | +Install django-munin into your python path with the usual pip install |
| 14 | +or whatever you are doing. Then add 'munin' to your INSTALLED_APPS and |
| 15 | +run 'manage.py syncdb' (it just needs to set up one database table |
| 16 | +that it will use for performance testing). |
| 17 | + |
| 18 | +To access the included basic views, add the following pattern to your |
| 19 | +urls.py: |
| 20 | + |
| 21 | + ('^munin/',include('munin.urls')), |
| 22 | + |
| 23 | +The views available there are then going to be at: |
| 24 | + |
| 25 | + * munin/db_performance/ (milliseconds to perform insert/select/delete operations) |
| 26 | + * munin/total_users/ (total number of Users) |
| 27 | + * munin/active_users/ (number of users logged in in the last hour) |
| 28 | + * munin/total_sessions/ (total number of sessions) |
| 29 | + * munin/active_sessions/ (number of sessions that are not expired) |
| 30 | + |
| 31 | +Those were the only metrics I could think of that would be potentially |
| 32 | +useful on just about any Django app and were likely to always be |
| 33 | +available. |
| 34 | + |
| 35 | +(I'm going to assume that you are already a pro at configuring |
| 36 | +Munin. If not, go get on that. Munin is very cool) |
| 37 | + |
| 38 | +Next, copy scripts/django.py into your /usr/share/munin/plugins/ |
| 39 | +directory. |
| 40 | + |
| 41 | +For each metric that you want Munin to monitor, make a symlink in |
| 42 | +/etc/munin/plugins/ to /usr/share/munin/plugins/django.py with an |
| 43 | +appropriate name. Eg, to monitor all five of the included ones (as |
| 44 | +root, probably): |
| 45 | + |
| 46 | + $ ln -s /usr/share/munin/plugins/django.py /etc/munin/plugins/myapp_db_performance |
| 47 | + $ ln -s /usr/share/munin/plugins/django.py /etc/munin/plugins/myapp_total_users |
| 48 | + $ ln -s /usr/share/munin/plugins/django.py /etc/munin/plugins/myapp_active_users |
| 49 | + $ ln -s /usr/share/munin/plugins/django.py /etc/munin/plugins/myapp_total_sessions |
| 50 | + $ ln -s /usr/share/munin/plugins/django.py /etc/munin/plugins/myapp_active_sessions |
| 51 | + |
| 52 | +You then need to configure each of them in |
| 53 | +/etc/munin/plugin-conf.d/munin-node |
| 54 | + |
| 55 | +For each, give it a stanza with env.url and graph_category set. To |
| 56 | +continue the above, you'd add something like: |
| 57 | + |
| 58 | + [myapp_db_performance] |
| 59 | + env.url http://example.com/munin/db_performance/ |
| 60 | + graph_category myapp |
| 61 | + |
| 62 | + [myapp_total_users] |
| 63 | + env.url http://example.com/munin/total_users/ |
| 64 | + graph_category myapp |
| 65 | + |
| 66 | + [myapp_active_users] |
| 67 | + env.url http://example.com/munin/active_users/ |
| 68 | + graph_category myapp |
| 69 | + |
| 70 | + [myapp_total_sessions] |
| 71 | + env.url http://example.com/munin/total_sessions/ |
| 72 | + graph_category myapp |
| 73 | + |
| 74 | + [myapp_active_sessions] |
| 75 | + env.url http://example.com/munin/active_sessions/ |
| 76 | + graph_category myapp |
| 77 | + |
| 78 | +Restart your Munin node, and it should start collecting and graphing |
| 79 | +that data. |
| 80 | + |
| 81 | +Those are pretty generic metrics though and the real power of this |
| 82 | +application is that you can easily expose your own custom |
| 83 | +metrics. Basically, anything that you can calculate in the context of |
| 84 | +a Django view in your application, you can easily expose to Munin. |
| 85 | + |
| 86 | +django-munin includes a 'muninview' decorator that lets you write a |
| 87 | +regular django view that returns a list of (key,value) tuples and it |
| 88 | +will expose those to that django.py munin plugin for easy graphing. |
| 89 | + |
| 90 | +The @muninview decorator takes a config parameter, which is just a |
| 91 | +string of munin config directives. You'll want to put stuff like |
| 92 | +graph_title, graph_vlabel, and graph_info there. Possibly |
| 93 | +graph_category too (if you include it there, remove it from the munin |
| 94 | +plugin conf stanza). The view function that it wraps then just needs |
| 95 | +to return a list of tuples. |
| 96 | + |
| 97 | +The simplest way to get a feel for how this works is to look at how |
| 98 | +the included views were written. So check out munin/views.py. |
0 commit comments