How do I install Graphite on CentOS?

Introduction

What is Graphite?

Graphite is a free metrics collection and plotting tool for Linux/UNIX systems.

Components

The Graphite suite is composed of three main components:

Carbon – this is the daemon process that listens on TCP/2003 for clients to deliver metrics to it. The metrics are stored in a Whisper database.
Diamond – client-side daemon to collect system statistics and deliver them to Carbon. Any tool written in any language can collect data and deliver it to Carbon on TCP/2003.
Graphite – the Python tool to do the actual plotting of the Whisper-stored data.

Installation

Install Python dependencies:

# mkdir -p /opt
# mkdir -p /data
# yum -y install python-pip
# yum -y install gcc
# yum -y install python-devel
# pip install carbon
# pip install whisper
# pip install graphite-web
# pip install -Iv 'https://www.djangoproject.com/download/1.5.5/tarball/'
# pip install daemonize
# pip install 'Twisted<12.0'
# pip install tagging
# pip install django-tagging

Change SECRET_KEY in /opt/graphite/webapp/graphite/settings.py
/opt/graphite/webapp/graphite/settings.py

 .
 .
 .
SECRET_KEY = 'ReallyHardPassword'
 .
 .
 .

Move /opt/graphite/storage to /data and set up a symlink:

# mkdir /data/graphite
# mv /opt/graphite/storage/ /data/graphite/
# ln -s /data/graphite/storage/ /opt/graphite/
#

Install Apache:

# yum -y install httpd
# chown apache:apache /opt/graphite/storage/log/webapp/
# yum -y install mod_wsgi
# yum -y install cairo
# yum -y install cairo-devel
# yum -y install pycairo
# yum -y install pycairo-devel

Configuration

Configure Carbon

# cp /opt/graphite/examples/example-graphite-vhost.conf  /etc/httpd/conf.d/graphite.conf
# cp /opt/graphite/conf/carbon.conf.example /opt/graphite/conf/carbon.conf
# cp /opt/graphite/conf/storage-schemas.conf.example /opt/graphite/conf/storage-schemas.conf

Change retention policy in storage-schemas.conf. Delete the "default_1min_for_1day" section and replace it with:

/opt/graphite/conf/storage-schemas.conf
[everything_1min_24months]
priority = 100
pattern = .*
retentions = 1m:730d

Configure Graphite

# cp /opt/graphite/webapp/graphite/local_settings.py.example /opt/graphite/webapp/graphite/local_settings.py
# cp /opt/graphite/conf/graphite.wsgi.example /opt/graphite/conf/graphite.wsgi

Configure Time Zone. Set the time zone in /opt/graphite/webapp/graphite/local_settings.py. Add:

TIME_ZONE = 'America/Los_Angeles'

Change SECRET_KEY in /opt/graphite/webapp/graphite/local_settings.py and set:

LOG_CACHE_PERFORMANCE = True

Set up the Graphite database and create an admin user

# cd /opt/graphite/
# python ./webapp/graphite/manage.py syncdb
 .
 .

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'root'): admin
Email address: my.email.address@my.isp
Password: ReallyHardPassword
Password (again): ReallyHardPassword
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
#
Make sure the webserver user owns the Graphite database:
# chown apache:apache /opt/graphite/storage/graphite.db
# chown apache:apache /opt/graphite/storage/

Set up Apache. Comment out "WSGISocketPrefix" and add "WSGISocketPrefix /var/run/httpd/wsgi" in /etc/httpd/conf.d/graphite.conf, and set ServerName:

 .
 .
#WSGISocketPrefix run/wsgi
WSGISocketPrefix /var/run/httpd/wsgi

<VirtualHost *:80>
        ServerName graphite

 .
 .

Start up Carbon and Graphite (Apache):

# /opt/graphite/bin/carbon-cache.py start

# service httpd start

Set it up to start automatically at boot:

# cd /usr/src
# wget 'https://gist.github.com/DrPheltRight/1071989/raw/32b8da693933ccc5b04445c13ec280a622f61400/carbon.init.sh'

# mv carbon.init.sh /etc/init.d/carbon
Edit /etc/init.d/carbon and change:
/etc/init.d/carbon
/usr/local/lib/python2.6/dist-packages/
... to: ...
/etc/init.d/carbon
/usr/lib/python2.6/site-packages/
Configure for auto-start at boot:
# chmod 755 /etc/init.d/carbon
# /sbin/chkconfig httpd on
# /sbin/chkconfig --add carbon
Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Twitter
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • StumbleUpon

4 Comments

  1. i could not syncdb myself a new database. it kept complaining that module could not be loaded.
    (2.6.32-431.17.1.el6.x86_64)
    so i poked at
    vim /usr/lib/python2.6/site-packages/django/db/backends/sqlite3/base.py
    and edited the header to try the “new” following…

    try:
    from sqlite3 import dbapi2 as Database
    except ImportError as exc:
    from django.core.exceptions import ImproperlyConfigured
    raise ImproperlyConfigured(“Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s” % exc)

    —- apart from that, i loved the documentation and explanation.
    many thanks!

  2. I faced an issue after setting it up where the graphs didn’t get rendered, digging further it was found to be due to missing fonts. Installing bitmap-fonts fixed that problem.

    yum install bitmap-fonts

    Which installed all these packages

    Installed:
    bitmap-fonts-compat.noarch 0:0.3-15.el6

    Dependency Installed:
    bitmap-console-fonts.noarch 0:0.3-15.el6 bitmap-fangsongti-fonts.noarch 0:0.3-15.el6
    bitmap-fixed-fonts.noarch 0:0.3-15.el6 bitmap-lucida-typewriter-fonts.noarch 0:0.3-15.el6
    bitmap-miscfixed-fonts.noarch 0:0.3-15.el6 fontpackages-filesystem.noarch 0:1.41-1.1.el6

    Thanks again! :)

  3. Great article! Many thanks!

    Since I used a minimal CentOS installation, I had to install the bitmap-fonts.
    Also, I had to configure the database name in /opt/graphite/webapp/graphite/settings.py — would run into a database locked exception otherwise.

    Cheers — Robin

Leave a Reply

Your email address will not be published. Required fields are marked *