Graphite and Nginx

I have been working on Graphite for a while and the one thing I didn’t like much was having to use Apache. It took some time to get it right, but I have eventually set it up to use supervisor, uwsgi and nginx. I have installed graphite 0.9.9 from sources. This setup is on a Debian stable system. First things first, a few packages to install: apt-get install python-dev libxml2-dev build-essential python-django-tagging. Then unpack carbon, whisper and graphite-web in that order and install them (default directory is /opt/graphite).

Then you need to grab uwsgi and unpack it and cd into the directory, you are now required to run this:

[sourcecode language="xml"]
wget http://projects.unbit.it/downloads/uwsgi-0.9.9.2.tar.gz
tar xf uwsgi-0.9.9.2.tar.gz
cd uwsgi-0.9.9.2
make -f Makefile.Py26
cp uwsgi /usr/local/bin/
cp nginx/uwsgi_params /etc/nginx/
[/sourcecode]

All is well in the universe, it is time to configure supervisor (apt-get install supervisor). Then create a file called /etc/supervisor/conf.d/uwsgi.conf and put that in. To restart supervisor, make sure you do a stop/start. Restart is flaky for me.
[sourcecode language="xml"]
[program:uwsgi]
command=/usr/local/bin/uwsgi
–module ‘django.core.handlers.wsgi:WSGIHandler()’
–socket 127.0.0.1:3031
–chdir /opt/graphite/webapp
–processes 1
–master
–harakiri 120
–max-requests 5000
–pythonpath "['/opt/graphite/webapp'] + sys.path"
directory=/opt/graphite/webapp
environment=DJANGO_SETTINGS_MODULE=’graphite.settings’
user=www-data
autostart=true
autorestart=true
stdout_logfile=/var/log/nginx/uwsgi.log
redirect_stderr=true
stopsignal=QUIT
[/sourcecode]
Next is to get your nginx config right, keep in mind that i use a directory within a vhost for graphite, so your config will differ if you use graphite as /, here is my full config:
[sourcecode language="xml"]
server {
listen 80;
listen [::]:80; # use this only if using IPv6
client_max_body_size 4M;
server_name graphite.frlinux.net;
root /var/www/stats;
access_log /var/log/nginx/stats.access.log;
error_log /var/log/nginx/stats.error.log;

location / {
}
location /graphite/ {
gzip off;
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
}
location /content {
alias /opt/graphite/webapp/graphite/content;
gzip off;
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
}
location /metrics {
alias /opt/graphite/webapp/graphite/metrics;
gzip off;
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
}
location /dashboard {
alias /opt/graphite/webapp/graphite/dashboard;
gzip off;
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
}
location /render {
alias /opt/graphite/webapp/graphite/render;
gzip off;
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
}
location /browser {
alias /opt/graphite/webapp/graphite/browser;
gzip off;
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
}
location /composer {
alias /opt/graphite/webapp/graphite/composer;
gzip off;
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
}
}
[/sourcecode]
That’s it, point your browsers to your site like: http://site.example.com/graphite and it should be ready to show you data. Keep in mind that you have to take care of security which I am not covering in this article.

2 thoughts on “Graphite and Nginx

Comments are closed.