I spend the last two days installing Graphite on our server at mapado.

What we have:

  • Linux server with Debian Squeeze
  • Python 2.7 installed system-wide with python headers ( sudo apt-get install python-dev)
  • virtualenv and virtualenv-wrapper installed ( sudo pip install virtualenv virtualenv_wrapper)
  • cairo installed system-wide (apparently cairo dos not work fine with pip, so :  sudo apt-get install python-cairo)
  • Apache2 server running

What we wanted:

  • A Graphite instance running in his own virtualenv and accessible via http://graphite.example.com
  • A StatsD daemon
  • Monitor our Symfony2 project
  • Monitor our python projects

Here is what we have done to achieve that:

  • Configure our virtualenv
  • Install Graphite (+ requirements)
  • Configure Apache2 and a VirtualHost
  • Install StatsD
  • Configure our Symfony2 project

Configure virtualenv

Python’s virtualenv allow us to have a “blackbox” for our graphite project. It will be useful, because :

  • We do not want to install a lot of dependencies system-wide
  • Graphite’s dependancies needs to be on a special version

For informations, our virtualenv directory is /home/envs/

Install graphite

Now we have to install graphite (you have to still be working on your virtualenv).

Configure apache

Apache have several modules for Python but everyone seems to agree that WSGI is the one to use. So lets install it. sudo apt-get install libapache2-mod-wsgi

Create a file in your vhost :

Our vhost file, I was inspired by graphite’s example

Let’s activate our vhost and restart:

You can now try to open http://graphite.example.com. You should see the graphite interface. If not, you have a problem ! I may be able to help in the comments section.

Install StatsD

I follow this Gist for this step, without problem :

But before starting your statsd instance, you can activate debug mode like this, you will be able to see where does your application is failing (if you have a bug of course). Activate debug mode in local.js:

We assume your StatsD and graphite instance are on the same server, and you do not change the default port.

Test if StatD is up

You should see something like that:

Send your first packet to Graphite

Open a new terminal and type :

In your running StatsD terminal you should see something like :

In my shell, I also have a message like this: DEBUG: Bad line: 1 in msg "", but it works 😉

Change back your statsd local.js to something like :

And now….

Open your graphite url ( http://graphite.example.com in our example )

In “Graphite/stats_counts”, we now have a “website” folder, containing our website.index.views graph.

with PHP

As I work in a Symfony2 project, I used liuggio/statsd-client-bundle. If you do not work with Symfony, your are free to use any other library. Etsy provide a lot of examples here.

So I follow these steps

Your log should have the data to be send in your dev environment If you want to see them in your graphite instance, put debug: false in your connection options list (in your config.yml).

With Python

We did not plugged our python projects at the moments I wrote this article, but I think we will follow etsy’s exemple

 

Thanks to Balto Rouberol who helped me with the python stuff ! 😉

Sources: