Friday, February 3, 2012

Get Graphite run for a Django project

This post is intended first of all to memorize my experience of getting the Graphite system work.

Graphite system

Graphite is designed to install itself in /opt/graphite. There is no way to change it without getting a pain in the ass. I chose to install it in Ubuntu in VM without touching my system. Here we go to install Graphite.

Getting sources
mkdir -p ~/tmp/graphite-install/
cd ~/tmp/graphite-install/


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

Installing dependencies (only packages required to get it working)
sudo apt-get install python-setuptools
sudo easy_install django django_tagging

Install Whisper
cd whisper
sudo python install

Install Carbon
cd ../carbon
sudo python install
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
priority = 110
pattern = .*
retentions = 10:2160,60:10080,600:262974
# note, it does not allow comments in values and causes errors

install Graphite
cd ../graphite
sudo python
sudo python install

# initial database creation
cd /opt/graphite/webapp/graphite/
sudo python syncdb
### follow prompts to setup django admin user
sudo chown -R <your_user>:>your_user> /opt/graphite/storage/
sudo cp

# carbon
cd ../../
sudo ./bin/ start
## it will listen on 2003 port

# graphite web ui
cd webapp/graphite
python runserver

That's all with Graphite. Now let's organize data sending from your project to the Graphite instance we've made.


I launched the daemon locally, not in a virtual machine. To do it follow the steps:


First, activate a virtual environment (hope you use it)
pip install django-statsd-mozilla statsd

Configure django_statsd client. In
STATSD_CLIENT = 'django_statsd.clients.normal'
STATSD_HOST = 'localhost'
STATSD_PREFIX = 'your_prefix'
# Note, port number must be an integer (not '8125')
# as it causes an error deep inside.

If you're going to use django_statsd's middlewares and/or patches
pip install django-debug-toolbar

Collecting metrics
from django_statsd.clients import statsd
statsd.timing('', 123)  # in milliseconds

P.S. Thanks to Rob Goldings for inspiration.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.