Monday, October 3, 2011

Scalable realtime stats with Graphite

Introduction


Here at Adku, we’re always looking for ways to move faster and smarter.  There’s nothing worse than having to wait a day or two to see if a code push has a positive or negative effect on our bottom line.  One way to track application issues is to create a stat and graph it.  While there’s a litany of solutions out there today, we’re using Graphite, a realtime graphing framework and we love what its done for us thus far.  Here’s what Graphite can do:


We recently went through the process of setting up our own Graphite cluster and below are the references/steps that we used to get everything running.  We hope this helps :)


Graphite installation guide


This guide will install all the software packages required to get you up and running.  Graphite will be setup to run across multiple machines.  NOTE, these steps are virtually verbatim copies of our setup scripts.  We are assuming you’re working with a clean Ubuntu 10.04 LTS installation (we’re using Ubuntu AMIs on EC2)  We will NOT be delving into specifics for all non-Graphite related apps.  In case you’re curious, this guide will install the following packages:

Process control - supervisor - akin to init.d
Web serving - nginx, uwsgi - akin to apache + mod_wsgi/mod_python
Caching - memcached
Stats collection - statsite - akin to Etsy’s statsd without a dependency on node.js
Graphite - graphite-web, carbon, whisper - required for stats collection


Step 2 - Run bootstrap.sh

Step 3 - Copy all files from the archive into /etc and /opt respectively

Step 4 - Update following config variables

/etc/nginx/nginx.conf - worker processes (line 4)
/etc/nginx/sites-enabled/graphite - public hostname (line 3)
/etc/supervisor/supervisord.conf - web processes (line 39)
/opt/graphite/conf/carbon.conf - storage dir and cluster servers (line 2 and line 96)
/opt/graphite/conf/relay-rules.conf - cluster servers (line 3)
/opt/graphite/conf/storage-schemas.conf - retention times (line 4 - optional)
/opt/graphite/webapp/graphite/local_settings.py - storage dir and cluster servers (all lines)

Step 5 - Setup the graphite-web - Django app

cd /opt/graphite/webapp/graphite
yes no | python manage.py syncdb

Step 6 - Spin up supervisord - should spin up all other processes

sudo supervisorctl status
sudo supervisord (only if needed)

Step 7 - Ensure that our processes didn’t blow up

sudo tail -f /var/log/supervisor/*.log

Step 8 - Feed stats to your cluster.  For a list of clients see


Step 9 - Check your stats server that your stat showed up!

http://statsd.yourhost.com:7001/


Further reference

Graphite

nginx/uwsgi - used for web serving

statsite - Python implementation of Etsy’s statsd

20 comments:

  1. This article helps us a lot. I appreciate your help on sharing these guides. Thanks!

    Accounting Packages

    ReplyDelete
  2. Hi,

    Thanks

    I do all step to post, but i started supervisor and uWSGI don't started.

    This error is
    *** Starting uWSGI 1.4.5 (32bit) on [Wed Feb 20 18:30:36 2013] ***
    compiled with version: 4.6.3 on 20 February 2013 17:29:32
    os: Linux-3.6.11+ #377 PREEMPT Sat Feb 16 17:31:02 GMT 2013
    nodename: raspian
    machine: armv6l
    clock source: unix
    detected number of CPU cores: 1
    current working directory: /
    detected binary path: /usr/local/bin/uwsgi
    uWSGI running as root, you can use --uid/--gid/--chroot options
    *** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
    your processes number limit is 3377
    limiting address space of processes...
    your process address space limit is 536870912 bytes (512 MB)
    your memory page size is 4096 bytes
    detected max file descriptor number: 1024
    lock engine: pthread robust mutexes
    uwsgi socket 0 bound to TCP address 127.0.0.1:3031 fd 3
    Python version: 2.7.3 (default, Jan 13 2013, 12:38:42) [GCC 4.6.3]
    Fatal Python error: exceptions bootstrapping error.


    could you help me?


    ReplyDelete
  3. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai Java Training in Chennai

    Online Java Training Java Online Training | Java 8 online training | JavaEE Training in Chennai

    ReplyDelete
  4. Hibernate Training Institutes in ChennaiHibernate Training Institutes in Chennai Hibernate Online Training Hibernate Online Training Hibernate Training in Chennai Hibernate Training in Chennai Java Online Training Java Online Training

    ReplyDelete
  5. Struts2 Training Institutes in Chennai Struts2 Training Institutes in Chennai Spring Training Institutes in Chennai Spring Training Institutes in Chennai Java MicroServices Training Institutes In Chennai Java MicroServices Training Institutes In Chennai

    ReplyDelete