Merge lp:~muffinresearch/graphite/mod_wsgi_example into lp:~graphite-dev/graphite/main

Proposed by Stuart Colville
Status: Merged
Merge reported by: chrismd
Merged at revision: not available
Proposed branch: lp:~muffinresearch/graphite/mod_wsgi_example
Merge into: lp:~graphite-dev/graphite/main
Diff against target: 178 lines (+100/-11)
5 files modified
INSTALL (+33/-8)
README (+1/-1)
check-dependencies.py (+13/-2)
examples/example-graphite-mod-wsgi-vhost.conf (+34/-0)
webapp/graphite/graphite.wsgi (+19/-0)
To merge this branch: bzr merge lp:~muffinresearch/graphite/mod_wsgi_example
Reviewer Review Type Date Requested Status
chrismd Approve
Review via email: mp+27651@code.launchpad.net

Description of the change

This branch provides a basic example for running graphite under mod_wsgi along with updated docs.

The rationale behind this is that mod_python is not currently actively developed [1] and mod_wsgi is the recommended approach for using django in production with Apache. [2]

The branch retains the mod_python examples and instructions to be backwards compatible for existing users though I've written the docs adding a gentle emphasis that mod_wsgi is recommended.

[1] http://blog.dscpl.com.au/2010/05/modpython-project-soon-to-be-officially.html
[2] http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/

To post a comment you must log in.
Revision history for this message
chrismd (chrismd) wrote :

Sorry it took me so long to get around to looking at this. Some of this is already in trunk (the example vhost config) but merging in the INSTALL doc update, etc

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'INSTALL'
--- INSTALL 2010-03-25 15:01:48 +0000
+++ INSTALL 2010-06-15 18:55:42 +0000
@@ -18,7 +18,7 @@
18 pycairo (with PNG backend support)18 pycairo (with PNG backend support)
19 django19 django
20 json (standard in python2.6) or simplejson20 json (standard in python2.6) or simplejson
21 mod_python (optional - but highly recommended)21 mod_wsgi (optional, recommended) or mod_python (optional)
22 python-ldap (optional - needed for ldap-based webapp authentication)22 python-ldap (optional - needed for ldap-based webapp authentication)
23 python-memcached (optional - needed for webapp caching, big performance boost)23 python-memcached (optional - needed for webapp caching, big performance boost)
24 python-sqlite2 (optional - a django-supported database module is required)24 python-sqlite2 (optional - a django-supported database module is required)
@@ -67,13 +67,37 @@
6767
68 Apache Configuration68 Apache Configuration
69-------------------------------------------------------------------------------69-------------------------------------------------------------------------------
70First off, Apache has to have mod_python configured, this is usually done70When using apache there are two modules available to provide support for python
71by including a line like the following in your httpd.conf:71web application.
72
73Graphite currently provides example configurations for both of these modules.
74Of the two mod_wsgi is the most up to date and actively maintained so it's
75highly recommended if you are starting afresh.
76
77 Apache Configuration for Mod_wsgi (recommended)
78-------------------------------------------------------------------------------
79
80If you are using mod_wsgi, Apache has to have mod_wsgi configured,
81this is usually done by including a line like the following in your
82httpd.conf:
83
84LoadModule wsgi_module modules/mod_wsgi.so
85
86 Apache Configuration for Mod_python
87-------------------------------------------------------------------------------
88
89If you choose to use mod_python, Apache has to have mod_python configured,
90this is usually done by including a line like the following in your
91httpd.conf:
7292
73LoadModule python_module modules/mod_python.so93LoadModule python_module modules/mod_python.so
7494
75Second you should configure a vhost for graphite (technically it doesn't have95 General Apache Configuration
76to be a vhost but its good practice). This can be done one of two ways.96-------------------------------------------------------------------------------
97
98Once you have configured the apache module you are using you should configure
99a vhost for graphite (technically it doesn't have to be a vhost but its good
100practice). This can be done one of two ways.
77101
78The first way (highly preferred) is to include independent vhost configs.102The first way (highly preferred) is to include independent vhost configs.
79103
@@ -82,10 +106,11 @@
82106
83Then simply drop your graphite vhost conf file into the vhosts.d/ directory107Then simply drop your graphite vhost conf file into the vhosts.d/ directory
84(or whatever directory your system uses) and apache is ready. You can use108(or whatever directory your system uses) and apache is ready. You can use
85the examples/example-graphite-vhost.conf file included in this package as a109either of the example vhost confs as a starting point (See the examples
86starting point.110directory of this package and choose the correct one based on whether you
111are using mod_wsgi or mod_python.)
87112
88The second approach is to copy the contents of the graphite vhost conf file113The second approach is to copy the contents of your chosen graphite vhost conf file
89and insert it down at the end of your httpd.conf.114and insert it down at the end of your httpd.conf.
90115
91116
92117
=== modified file 'README'
--- README 2009-09-14 21:40:04 +0000
+++ README 2010-06-15 18:55:42 +0000
@@ -2,7 +2,7 @@
2-------------------------------------------------------------------------------2-------------------------------------------------------------------------------
3Graphite consists of two major components3Graphite consists of two major components
44
5 1) the frontend Django webapp that runs under mod_python Apache5 1) the frontend Django webapp that runs under Apache with mod_python or mod_wsgi
6 2) the backend carbon-cache.py daemon6 2) the backend carbon-cache.py daemon
77
8Client applications connect to the running carbon-cache.py daemon on port 2003 and send it8Client applications connect to the running carbon-cache.py daemon on port 2003 and send it
99
=== modified file 'check-dependencies.py'
--- check-dependencies.py 2010-03-25 15:01:48 +0000
+++ check-dependencies.py 2010-06-15 18:55:42 +0000
@@ -69,14 +69,25 @@
6969
7070
71# Test for mod_python71# Test for mod_python
72mod_python_installed = 0
72try:73try:
73 import mod_python74 import mod_python
75 mod_python_installed = 1
74except:76except:
75 print "[WARNING] Unable to import the 'mod_python' module, do you have mod_python installed for python %s?" % py_version77 print "[WARNING] Unable to import the 'mod_python' module, do you have mod_python installed for python %s?" % py_version
76 print "This means you will only be able to run graphite in the development server mode, which is not"78 print "This means you will only be able to run graphite under mod_wsgi (if installed)"
77 print "recommended for production use."79 print "OR the development server mode, which is not recommended for production use."
78 warning += 180 warning += 1
7981
82# Non-test for mod_wsgi
83print "[WARNING] Unable to reliably test for the presence of the 'mod_wsgi' module, do you have mod_wsgi installed?"
84print "Note: mod_wsgi is highly recommended for serving python web applications with Apache"
85mp_instructions = "mod_python (installed) \nOR " if mod_python_installed else ""
86print "If mod_wsgi is not installed you will only be able to run graphite "\
87 "under %sthe development server mode, which is not recommended for production use." % mp_instructions
88warning += 1
89
90
8091
81# Test for python-memcached92# Test for python-memcached
82try:93try:
8394
=== renamed file 'examples/example-graphite-vhost.conf' => 'examples/example-graphite-mod-python-vhost.conf'
=== added file 'examples/example-graphite-mod-wsgi-vhost.conf'
--- examples/example-graphite-mod-wsgi-vhost.conf 1970-01-01 00:00:00 +0000
+++ examples/example-graphite-mod-wsgi-vhost.conf 2010-06-15 18:55:42 +0000
@@ -0,0 +1,34 @@
1NameVirtualHost *:80
2
3# You may need to manually edit this file to fit your needs.
4# This configuration assumes the default installation prefix
5# of /opt/graphite/, if you installed graphite somewhere else
6# you will need to change all the occurances of /opt/graphite/
7# in this file to your chosen install location.
8
9<VirtualHost *:80>
10 DocumentRoot "/opt/graphite/webapp"
11
12 ErrorLog /opt/graphite/storage/log/webapp/error.log
13
14 WSGIDaemonProcess graphite user=www-data group=www-data threads=25
15 WSGIProcessGroup graphite
16
17 WSGIScriptAlias / /opt/graphite/webapp/graphite/graphite.wsgi
18
19 <Directory /opt/graphite/webapp>
20 Order deny,allow
21 Allow from all
22 </Directory>
23
24 # NOTE: In order for the django admin site media to work you
25 # must change @DJANGO_ROOT@ to be the path to your django
26 # installation, which is probably something like:
27 # /usr/lib/python2.6/site-packages/django
28 Alias /media/ "@DJANGO_ROOT@/contrib/admin/media/"
29 <Directory @DJANGO_ROOT@/contrib/admin/media>
30 Order deny,allow
31 Allow from all
32 </Directory>
33
34</VirtualHost>
035
=== added file 'webapp/graphite/graphite.wsgi'
--- webapp/graphite/graphite.wsgi 1970-01-01 00:00:00 +0000
+++ webapp/graphite/graphite.wsgi 2010-06-15 18:55:42 +0000
@@ -0,0 +1,19 @@
1# You may need to manually edit this file to fit your needs.
2# This configuration assumes the default installation prefix
3# of /opt/graphite/, if you installed graphite somewhere else
4# you will need to change all the occurances of /opt/graphite/
5# in this file to your chosen install location.
6
7import os
8import sys
9sys.path.insert(0, '/opt/graphite/webapp/')
10os.environ['DJANGO_SETTINGS_MODULE'] = 'graphite.settings'
11
12import django.core.handlers.wsgi
13
14_application = django.core.handlers.wsgi.WSGIHandler()
15
16def application(environ, start_response):
17 environ['PATH_INFO'] = environ['SCRIPT_NAME'] + environ['PATH_INFO']
18 return _application(environ, start_response)
19