Intro to Graphite

Introduction

Graphite is a powerful monitoring platform open sourced by Orbitz.com. It's written in Python, and relies on a collector, Carbon, to collect metrics. Graphite can use apache or nginx for web services using mod_python/python wsgi. 

Graphite has x main components:
  • Carbon Carbon is the collector and the web frontend. It serves as the main daemon that graphite needs to run.
  • Whisper This is the graphing database that graphite uses. It serves the same purpose as RRD, You can read more about it here.

Installation

Installation is mostly a manual build process. There are two methods, from source, or using python's pip packaging service. Since pip is simpler I'll be documenting this method. At the time of this writing, there are no supported Ubuntu packages for Graphite.

# BASIC REQUIREMENTS
# http://graphite.wikidot.com/installation
# http://server.dzone.com/articles/installing-graphite-099-ubuntu
####################################

VERSION="0.9.10"
 
sudo apt-get update
sudo apt-get upgrade

# Some of these may not be needed
apt-get install memcached python-dev python-pip sqlite3 libcairo2 libcairo2-dev python-cairo python-django python-ldap python-memcache pkg-config libapache2-mod-python libapache2-mod-wsgi libapache2-mod-python apache2 libapache2 erlang-os-mon erlang-snmp rabbitmq-server

sudo pip install --upgrade pip
sudo pip install django-tagging

#
# Install Whisper
sudo pip install https://launchpad.net/graphite/0.9/$VERSION/+download/whisper-$VERSION.tar.gz
#
# Install and configure carbon
#
sudo pip install https://launchpad.net/graphite/0.9/$VERSION/+download/carbon-$VERSION.tar.gz
sudo cp carbon.conf.example carbon.conf
sudo cp storage-schemas.conf.example storage-schemas.conf
#
# Install Graphite
#
sudo pip install https://launchpad.net/graphite/0.9/$VERSION/+download/graphite-web-$VERSION.tar.gz

# CONFIGURE APACHE
#
cd /opt/graphite/examples
cp example-graphite-vhost.conf /etc/apache2/sites-available/graphite-vhost.conf
cd /opt/graphite/conf
cp graphite.wsgi.example graphite.wsgi
mkdir -p /etc/httpd/wsgi


sudo cp example-graphite-vhost.conf /etc/apache2/sites-available/graphite
# You'll probably want to edit /etc/apache2/sites-available/graphite 
# You'll definately want to change WSGISocketPrefix to be /var/run/wsgi 
sudo cp /opt/graphite/conf/graphite.wsgi.example /opt/graphite/conf/graphite.wsgi

sudo mkdir /etc/httpd
sudo mkdir /etc/httpd/wsgi
sudo a2ensite graphite
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

####################################
# 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

Post script actions:
Created a user carbon
edit /opt/graphite/conf/carbon.conf for USER to be carbon
chown -R carbon /opt/graphite/storage
chown -R www-data /opt/graphite/log/webapp
Added an init script found here.
Now carbon will start on startup.

Configuration/Layout

Graphite lives in /opt/graphite. Here are some highlights:

Graphite
carbon.conf This hold's the main carbon configs. Also holds the configs that get it to pull data from rabbitmq. It also defines the listeners, and many other directives. See the carbon.conf.example for a full list.
storage-schemas.conf The cheif purpose of this file is to define data retention periods. We have 1min data stored for 90 days, and 1hour data stored for 10years as of today.

After the above install, a very minimal configuration file was created which uses AMQP (rabbitmq) and sensu. It's important to note these directives go into the [cache] section. See the attached carbon.conf for the full configuration.

Apache
The main apache config is in /etc/apache2/sites-enabled/graphite. It's important to note that from the default file. This was edited from the default sample provided with graphite (example-graphite-vhost.conf).

Logs
Logs can be found in: 
  • /opt/graphite/storage/log/carbon-cache/carbon-cache-a 
  • /opt/graphite/storage/log/carbon-cache/webapp
There's a crontab that is rotating them in /etc/cron.d/graphite-log-rotation

Graph Storage
Graphs are stored in /opt/graphite/storage/whisper via a directory hierarchy.

References

Comments