How-to Install Graphite on Ubuntu

UPDATED TO WORK WITH GRAPHITE 0.9.9!!! (10/13/2011)

The new release of Graphite 0.9.9 includes an experimental Flot JavaScript graph. Awesome!

Steps to installing Graphite on Ubuntu -> gist.github.com
Ubuntu Graphite install screencast -> youtube.com

 If you are looking for a how-to on graphite one (CAD) or statsd this is not the place.

A few months ago I blogged abou how much I love stats. One of the things that I shared in that post was a blog post done by the etsy developer team about statsd and graphite to track everything.

This week I was able to get graphite setup on a dedicated Ubuntu 10.04 on my Mac using VMware Fusion. I thought I would share the steps I took so others might be able to save some time in their setup. In setting up apache I just copied over the default virtual host settings since graphite will be the only thing running on the server. If you are planning on having multiple virtual hosts on the machine then you will want to configure the virtual hosts differently.

####################################
# BASIC REQUIREMENTS
# http://graphite.wikidot.com/installation
# http://geek.michaelgrace.org/2011/09/how-to-install-graphite-on-ubuntu/
# Last tested & updated 10/13/2011
####################################

sudo apt-get update
sudo apt-get upgrade

wget http://launchpad.net/graphite/0.9/0.9.9/+download/graphite-web-0.9.9.tar.gz
wget http://launchpad.net/graphite/0.9/0.9.9/+download/carbon-0.9.9.tar.gz
wget http://launchpad.net/graphite/0.9/0.9.9/+download/whisper-0.9.9.tar.gz
tar -zxvf graphite-web-0.9.9.tar.gz
tar -zxvf carbon-0.9.9.tar.gz
tar -zxvf whisper-0.9.9.tar.gz
mv graphite-web-0.9.9 graphite
mv carbon-0.9.9 carbon
mv whisper-0.9.9 whisper
rm carbon-0.9.9.tar.gz
rm graphite-web-0.9.9.tar.gz
rm whisper-0.9.9.tar.gz
sudo apt-get install --assume-yes apache2 apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libapr1 libaprutil1 libaprutil1-dbd-sqlite3 python3.1 libpython3.1 python3.1-minimal libapache2-mod-wsgi libaprutil1-ldap memcached python-cairo-dev python-django python-ldap python-memcache python-pysqlite2 sqlite3 erlang-os-mon erlang-snmp rabbitmq-server bzr expect ssh libapache2-mod-python python-setuptools
sudo easy_install django-tagging

####################################
# INSTALL WHISPER
####################################

cd ~/whisper
sudo python setup.py install

####################################
# INSTALL CARBON
####################################

cd ~/carbon
sudo python setup.py install
# CONFIGURE CARBON
####################
cd /opt/graphite/conf
sudo cp carbon.conf.example carbon.conf
sudo cp storage-schemas.conf.example storage-schemas.conf
sudo vim storage-schemas.conf
### edited storage-schemas.conf to be the following
[stats]
priority = 110
pattern = .*
retentions = 10:2160,60:10080,600:262974
###

####################################
# CONFIGURE GRAPHITE (webapp)
####################################

cd ~/graphite
sudo python check-dependencies.py
sudo python setup.py install

# CONFIGURE APACHE
###################
cd ~/graphite/examples
sudo cp example-graphite-vhost.conf /etc/apache2/sites-available/default
sudo cp /opt/graphite/conf/graphite.wsgi.example /opt/graphite/conf/graphite.wsgi
sudo vim /etc/apache2/sites-available/default
# moved 'WSGIImportScript /opt/gr..' to right before virtual host since it gave me an error saying
# WSGIImportScript cannot occur within  section
# if this path does not exist make it!!!!!!
# /etc/httpd/wsgi
sudo mkdir /etc/httpd
sudo mkdir /etc/httpd/wsgi
sudo /etc/init.d/apache2 reload

####################################
# INITIAL DATABASE CREATION
####################################
cd /opt/graphite/webapp/graphite/
sudo python manage.py syncdb
# follow prompts to setup django admin user
sudo chown -R www-data:www-data /opt/graphite/storage/
sudo /etc/init.d/apache2 restart
cd /opt/graphite/webapp/graphite
sudo cp local_settings.py.example local_settings.py

####################################
# START CARBON
####################################
cd /opt/graphite/
sudo ./bin/carbon-cache.py start

####################################
# SEND DATA TO GRAPHITE
####################################
cd ~/graphite/examples
sudo chmod +x example-client.py
# [optional] edit example-client.py to report data faster
# sudo vim example-client.py
sudo ./example-client.py

Original installation instructions -> http://graphite.wikidot.com/installation

Looking to run an Ubuntu instance on EC2? Check out http://uec-images.ubuntu.com/releases/10.04/release/

Now you are ready to install StatsD!

MikeGrace: A 25 year old Geek that loves his wife and enjoys tech, photography, outdoors, and his motorcycle.

Discussion

  1. Nahum Wild says:

    Thanks for documenting this, worked like a charm :-)

  2. Todd Zusman says:

    Before running python check-dependencies.py, I had to run the following commands to ensure dependencies were met:

    apt-get install build-essential python2.6-dev
    easy_install zope.interface
    easy_install twisted
    easy_install txamqp

  3. Rex R. says:

    Todd is correct – the above instructions won’t work on a fresh Ubuntu install without Twisted and the other dependencies. Can you add these to your instructions so others won’t get tripped up here?

  4. Rex R. says:

    Also, the Flot graph stuff won’t work with Python 2.6+ without a change to /opt/graphite/webapp/graphite/graphlot and changing line 6 from:

    import simplejson
    to
    import json as simplejson

    You’ll get a Django error otherwise when you try to go that page

  5. MikeGrace says:

    Thanks for the updates Todd & Rex. I’ll have to go through the installation process again to see how it goes. : )

  6. JS Labonte says:

    Thank you !
    I hate having to fiddle too much with things on the week-end, you made my graphite setup a 5 minutes operation :)
    I’m now going to try and dicover it’s possibilities.

  7. Awesome article mate, thanks for this. Graphite was proving to be a nightmare to get up and running, but following your guide I just booted a cloud server and was sorted in 15 minutes.

    To clarify what Rex said you need to edit the file /opt/graphite/webapp/graphite/graphlot/views.py to get flot working.

    Also if you want on linux you can do sudo mkdir -p /etc/httpd/wsgi instead of the 2 mkdir lines, as it will create the parent structure. Wont make much difference to this script but may help you on others.

    Thanks for this, time to play with graphite!

  8. Jens Braeuer says:

    Thanks for this post. However I dislike manually installing stuff, so I created proper .deb packages (including txamqp) ;-)
    Find the shell-script to create .deb here: https://gist.github.com/1715985

  9. wingZero says:

    Hi,

    I am getting the below error any ideas?

    Cheers

    wingZero
    [Tue Feb 07 16:45:26 2012] [error] mod_wsgi (pid=16852): Target WSGI script ‘/opt/graphite/conf/graphite.wsgi’ cannot be loaded as Python module.
    [Tue Feb 07 16:45:26 2012] [error] mod_wsgi (pid=16852): Exception occurred processing WSGI script ‘/opt/graphite/conf/graphite.wsgi’.
    [Tue Feb 07 16:45:26 2012] [error] Traceback (most recent call last):
    [Tue Feb 07 16:45:26 2012] [error] File “/opt/graphite/conf/graphite.wsgi”, line 14, in
    [Tue Feb 07 16:45:26 2012] [error] from graphite.logger import log
    [Tue Feb 07 16:45:26 2012] [error] File “/usr/local/lib/python2.7/dist-packages/graphite_web-0.9.9-py2.7.egg/graphite/logger.py”, line 75, in
    [Tue Feb 07 16:45:26 2012] [error] log = GraphiteLogger() # import-shared logger instance
    [Tue Feb 07 16:45:26 2012] [error] File “/usr/local/lib/python2.7/dist-packages/graphite_web-0.9.9-py2.7.egg/graphite/logger.py”, line 40, in __init__
    [Tue Feb 07 16:45:26 2012] [error] self.infoHandler = Rotater(self.infoLogFile,when=”midnight”,backupCount=1)
    [Tue Feb 07 16:45:26 2012] [error] File “/usr/lib/python2.7/logging/handlers.py”, line 171, in __init__
    [Tue Feb 07 16:45:26 2012] [error] BaseRotatingHandler.__init__(self, filename, ‘a’, encoding, delay)
    [Tue Feb 07 16:45:26 2012] [error] File “/usr/lib/python2.7/logging/handlers.py”, line 65, in __init__
    [Tue Feb 07 16:45:26 2012] [error] logging.FileHandler.__init__(self, filename, mode, encoding, delay)
    [Tue Feb 07 16:45:26 2012] [error] File “/usr/lib/python2.7/logging/__init__.py”, line 893, in __init__
    [Tue Feb 07 16:45:26 2012] [error] StreamHandler.__init__(self, self._open())
    [Tue Feb 07 16:45:26 2012] [error] File “/usr/lib/python2.7/logging/__init__.py”, line 912, in _open
    [Tue Feb 07 16:45:26 2012] [error] stream = open(self.baseFilename, self.mode)
    [Tue Feb 07 16:45:26 2012] [error] IOError: [Errno 2] No such file or directory: ‘/usr/local/lib/python2.7/dist-packages/storage/log/webapp/info.log’
    [Tue Feb 07 16:45:26 2012] [error] StreamHandler.__init__(self, self._open())
    [Tue Feb 07 16:45:26 2012] [error] File “/usr/lib/python2.7/logging/__init__.py”, line 912, in _open
    [Tue Feb 07 16:45:26 2012] [error] stream = open(self.baseFilename, self.mode)
    [Tue Feb 07 16:45:26 2012] [error] IOError: [Errno 2] No such file or directory: ‘/usr/local/lib/python2.7/dist-packages/storage/log/webapp/info.log’
    [Tue Feb 07 16:45:26 2012] [error] Could not import graphite.local_settings, using defaults!

  10. Mohan says:

    All the steps before this completed. Any advice ?

    sudo python manage.py syncdb
    Traceback (most recent call last):
    File “manage.py”, line 11, in
    execute_manager(settings)
    File “/usr/lib/pymodules/python2.7/django/core/management/__init__.py”, line 438, in execute_manager
    utility.execute()
    File “/usr/lib/pymodules/python2.7/django/core/management/__init__.py”, line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
    File “/usr/lib/pymodules/python2.7/django/core/management/base.py”, line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
    File “/usr/lib/pymodules/python2.7/django/core/management/base.py”, line 220, in execute
    output = self.handle(*args, **options)
    File “/usr/lib/pymodules/python2.7/django/core/management/base.py”, line 351, in handle
    return self.handle_noargs(**options)
    File “/usr/lib/pymodules/python2.7/django/core/management/commands/syncdb.py”, line 56, in handle_noargs
    cursor = connection.cursor()
    File “/usr/lib/pymodules/python2.7/django/db/backends/__init__.py”, line 252, in cursor
    cursor = util.CursorWrapper(self._cursor(), self)
    File “/usr/lib/pymodules/python2.7/django/db/backends/sqlite3/base.py”, line 207, in _cursor
    self.connection = Database.connect(**kwargs)
    pysqlite2.dbapi2.OperationalError: unable to open database file
    fssadmin@fSSCHNDLINUX:~/graphite/graphite-web-0.9.9/webapp/graphite$

  11. Dan says:

    Willing to give this a try. Been looking for a way to do this for a long time.

  12. Jason MacLulich says:

    Extremely useful! Saved me a lot of time; the only problem I had was after I updated everything the PHP module for Apache2 had disappeared so I had to restore it with: apt-get install libapache2-mod-php5.

  13. x says:

    what is the intension of the change done in glyph.py?

  14. Jana Reddy says:

    Hi… I am very new to Ubuntu. This made me so much of help.
    Thanks for the blog.

    But I am getting an error like below.
    any suggestions…..

    when I am executing

    $ sudo /etc/init.d/apache2 reload

    Syntax error on line 17 of /etc/apache2/sites-enabled/graphite:
    Invalid command ‘WSGISocketPrefix’, perhaps misspelled or defined by a module not included in the server configuration
    …fail!

  15. Jim Geurts says:

    Updated for Graphite v0.9.10 and Ubuntu v12.04: https://gist.github.com/3112065

  16. Anna says:

    People who has such problem:
    [DATE] [error] mod_wsgi (pid=16852): Target WSGI script ‘/opt/graphite/conf/graphite.wsgi’ cannot be loaded as Python module.

    cheak out this
    /etc/apache2/mods-available
    wsgi.conf
    find the string WSGISocketPrefix
    it should be like WSGISocketPrefix /var/run/apache2/wsgi

    /etc/apache2/sites-available
    default
    find the string WSGISocketPrefix
    it should be the same as in the previous file

    be sure that you wrote twice the same!

  17. Fazz says:

    Hi. I am very new with graphite.
    Can i ask something, Can we use Dtrace with Graphite with different OS?
    Example like Dtrace on Solaris and Graphite on Ubuntu?
    Thanks everything.

  18. Douglas Muth says:

    I can also confirm that these installation instructions work for Amazon Linux on AWS EC2 servers. :-)

    Thank you for posting them. Saved me lots of effort and frustration.

  19. Josh says:

    The default django installation that ubuntu tries to install is 1.4 which the syncdb command is broken in. Reverted to 1.35 and it worked fine.

  20. Dhanushanth says:

    This article is really full for my project . Awesome steps … and video tutorial is super … keep it up.. and thanks ..

  21. Tsaavik says:

    Wish I had seen this url first. About 1000x easier
    http://graphite.readthedocs.org/en/0.9.10/install-pip.html

  22. Amit says:

    You are a rockstar !

  23. Leandro López (inkel) says:

    Thanks for this! I’ve found it very useful.

    Do you know where can I configure the number of rabbitmq processes that are being spawned?

  24. Nam Nguyen says:

    I also decided to write up an auto-install Graphite script on Ubuntu 12.04, you can check it out at: https://github.com/gdbtek/setup-graphite and https://github.com/gdbtek/setup-statsd, also CloudFormation template is provided at: https://github.com/gdbtek/cloudformation-templates.

  25. MikeGrace says:

    That’s great! Thanks Nam!

  26. arushi verma says:

    Thanks a lot

  27. Matt says:

    This is fantastic, worked like a charm! Thanks so much for posting.
    What is the easiest way of changing the sensor addresses to a more user-friendly name?

  1. [... UPDATED TO WORK WITH GRAPHITE 0.9.9!!! (10/13/2011) The new release of Graphite 0.9.9 includes an experimental Flot JavaScript graph. Awesome! Steps to installing Graphite on Ubuntu -> gist.github.com Ubuntu Graphite install screencast -> ...]

  2. [... UPDATED TO WORK WITH GRAPHITE 0.9.9!!! (10/13/2011) The new release of Graphite 0.9.9 includes an experimental Flot JavaScript graph. Awesome! Steps to installing Graphite on Ubuntu -> gist.github.com Ubuntu Graphite install screencast -> ...]

  3. [... UPDATED TO WORK WITH GRAPHITE 0.9.9!!! (10/13/2011) The new release of Graphite 0.9.9 includes an experimental Flot JavaScript graph. Awesome! Steps to installing Graphite on Ubuntu -> gist.github.com Ubuntu Graphite install screencast -> ...]