Using Graphite in Ubuntu 12.10

Graphite is an amazing tool for visualizing all kind of data.

This tutorial shows you how I installed Graphite on an Ubuntu Server 12.10.

First of all Graphite is built in Python on top of the framework Django and the application itself has 3 main parts:

Graphite-web, which generate graphs and handle dashboard, etc.
Carbon, which is a storage engine that aggregate data and store it in specialized database
Whisper, which is a specialized database
Moreover you will need a Webserver like apache to run the web app, you could be using anyserver you want, then if your application is node made in Python you will need a bridge-app that will relay any data from your application into Carbon, for this I used statsd (a simple nodeJs application).

I would switch to a root user (sudo su) from now, or you can put sudo infront each command.

apt-get update
apt-get install --assume-yes apache2 apache2-mpm-worker libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libapache2-mod-wsgi libaprutil1-ldap memcached python-cairo python-cairo-dev python-django python-ldap python-memcache python-pysqlite2 sqlite3 ssh libapache2-mod-python python-setuptools build-essential python-dev

easy_install zope.interface
easy_install twisted
easy_install txamqp
easy_install django-tagging

cd /root/
tar -zxvf graphite-web-0.9.10.tar.gz
tar -zxvf carbon-0.9.10.tar.gz
tar -zxvf whisper-0.9.10.tar.gz
rm carbon-0.9.10.tar.gz
rm graphite-web-0.9.10.tar.gz
rm whisper-0.9.10.tar.gz

Setting-up Carboon, Whisper and Graphite-web

cd /root/whisper-0.9.10/
python install

cd /root/carbon-0.9.10/
python install

cd /opt/graphite/conf
cp carbon.conf.example carbon.conf
cp storage-schemas.conf.example storage-schemas.conf
cp storage-aggregation.conf.example storage-aggregation.conf

This part will install graphite-web

cd /root/graphite-web-0.9.10/
// make sure dependencies are met
python install

// Copy wsgi script for apache
cp /opt/graphite/conf/graphite.wsgi.example /opt/graphite/conf/graphite.wsgi
cd /opt/graphite/webapp/graphite/
Then edit “/opt/graphite/webapp/graphite/”, i did:

Set timezone
Set memcache servers (to in my case)
Set database, in my case just uncomment the one for Django 1.2
Now we can initialize the DB:

cd /opt/graphite/webapp/graphite/
python syncdb
// create a user
// set a password

Setting-up Apache 2

cd /opt/graphite/examples/
cp example-graphite-vhost.conf /etc/apache2/sites-available/graphite
cd /etc/apache2/sites-enabled/
ln -s ../sites-available/graphite graphite

Edit “/etc/apache2/sites-available/graphite”, and change the following:

Servername to something you want
Logs to:
ErrorLog /var/log/apache2/graphite.error.log
CustomLog /var/log/apache2/graphite.access.log common
“WSGISocketPrefix run/wsgi” into “WSGISocketPrefix /var/run/apache2/wsgi” very important or you will get an error “Unable to connect to WSGI daemon process ‘graphite’”

You now need to change permission on the storage or you web server won’t work you can do:

chown -R www-data:www-data /opt/graphite/storage/
// Restart apache
service apache2 restart
Starting Carbon as a service

Carbon need to be started in order to save data into it, you can start carbon in command line like this:

cd /opt/graphite
sudo ./bin/ start
However this is not efficient, since if you reboot you server you will have to start carbon manually. To fix this we can create a service script.
Create a new file “/etc/init.d/carbon” and add the following into it:

#! /bin/sh
# /etc/init.d/carbon

# Some things that run always
touch /var/lock/carbon


# Carry out specific functions when asked to by the system
case "$1" in
        echo "Starting script carbon "
        su $CARBON_USER -c "cd $GRAPHITE_HOME"; su $CARBON_USR -c "$GRAPHITE_HOME/bin/ start"
        echo "Stopping script carbon"
        su $CARBON_USER -c "cd $GRAPHITE_HOME"; su $CARBON_USR -c "$GRAPHITE_HOME/bin/ stop"
        echo "Usage: /etc/init.d/carbon {start|stop}"
        exit 1

exit 0

Then change it’s permission to executable (“chmod 777 /etc/init.d/carbon”) and also register this script with Ubuntu “update-rc.d carbon defaults”. Now you can start carbon with this command line “/etc/init.d/carbon start” and if you server reboot, Carbon will be started automatically.

Finally you should be able to access Graphite Dashboard at the following address “http://yourServerName/” where you should be able to access the basic Graph that Carbon generate for itself.

You can also run this command “python /opt/graphite/examples/” which will send some data to Graphite about your system.

In my next post I will show you how to install Statsd and how to use it with your web application.

Django have been upgraded with the lastest version of Ubuntu and one of the function that Graphite use was deprecated in Djandgo 1.4 (execute_manager)

The error that you will get while running “python syncdb”

Traceback (most recent call last):
    File "", line 2, in 
        from import execute_manager
    ImportError: cannot import name execute_manager
To fixed this you’ll have to remove Django (“apt-get remove python-django”), install pip (“apt-get install python-pip”) and then install a version of Django lower than 1.5 (“pip install –upgrade 'Django<1.5’”)

Then you should be able to run “python syncdb” without any error

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s