Skip to content

Instantly share code, notes, and snippets.

@ashrithr
Last active September 27, 2020 20:10
Show Gist options
  • Save ashrithr/9224450 to your computer and use it in GitHub Desktop.
Save ashrithr/9224450 to your computer and use it in GitHub Desktop.
Installing graphite 0.10, collectd and grafana on centos 6

Graphite does two things:

  1. Store numeric time-series data
  2. Render graphs of this data on demand

What Graphite does not do is collect data for you, however there are some tools out there that know how to send data to graphite. Even though it often requires a little code, sending data to Graphite is very simple.

Architecture:

Graphite consists of 3 software components:

  • carbon - a Twisted daemon that listens for time-series data
  • whisper - a simple database library for storing time-series data (similar in design to RRD)
  • graphite webapp - A Django webapp that renders graphs on-demand using Cairo

Installing dependencies:

curl -o epel.rpm -L http://download.fedoraproject.org/pub/epel/6/$(arch)/epel-release-6-8.noarch.rpm

yum install gcc zlib-devel curl curl-devel openssl rpm-build gcc-c++ rpm-build python python-ldap python-memcached python-sqlite2 pycairo python-twisted Django python-django-tagging bitmap bitmap-fonts python-devel glibc-devel gcc-c++ openssl-devel python-zope-interface httpd memcached mod_wsgi wget

Install whisper, as both Carbon and Graphite require it

wget https://launchpad.net/graphite/0.9/0.9.10/+download/whisper-0.9.10.tar.gz
tar zxf whisper-0.9.10.tar.gz
cd whisper-0.9.10/
sudo python2.6 setup.py install
cd ..

Install carbon

wget https://launchpad.net/graphite/0.9/0.9.10/+download/carbon-0.9.10.tar.gz
tar zxf carbon-0.9.10.tar.gz
cd carbon-0.9.10/
sudo python2.6 setup.py install
cd ..
```

Install graphite webapp

```
wget https://launchpad.net/graphite/0.9/0.9.10/+download/graphite-web-0.9.10.tar.gz
tar zxf graphite-web-0.9.10.tar.gz
cd graphite-web-0.9.10/
./check-dependencies.py
```

once all dependencies are met...

```
sudo python2.6 setup.py install
```

This will install whisper as a site package and carbon and graphite will be installed into `/opt/graphite`

Configuring:

```
cd /opt/graphite/conf/
cp graphite.wsgi.example graphite.wsgi
cp storage-schemas.conf.example storage-schemas.conf
cp carbon.conf.example carbon.conf
cd ../webapp/graphite
cp local_settings.py.example local_settings.py
```

Uncomment the database engine in `local_settings.py` and then initialize the database by running the following command

```
python /opt/graphite/webapp/graphite/manage.py syncdb
```

Configuring httpd and wsgi:

```
cat > /etc/httpd/conf.d/wsgi.conf <<EOF
LoadModule wsgi_module modules/mod_wsgi.so
WSGISocketPrefix /var/run/wsgi
EOF
```

```
cat > /etc/httpd/conf.d/graphite.conf <<EOF
<IfModule !wsgi_module.c>
    LoadModule wsgi_module modules/mod_wsgi.so
</IfModule>

WSGISocketPrefix /var/run/wsgi

<VirtualHost *:80>
        ServerName $(hostname -f)
        DocumentRoot "/opt/graphite/webapp"
        ErrorLog /var/log/httpd/graphite_error.log
        CustomLog /var/log/httpd/graphite_access.log common

        WSGIDaemonProcess graphite processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120
        WSGIProcessGroup graphite
        WSGIApplicationGroup %{GLOBAL}
        WSGIImportScript /opt/graphite/conf/graphite.wsgi process-group=graphite application-group=%{GLOBAL}

        WSGIScriptAlias / /opt/graphite/conf/graphite.wsgi

        Alias /content/ /opt/graphite/webapp/content/
        <Location "/content/">
                SetHandler None
        </Location>

        Alias /media/ "@DJANGO_ROOT@/contrib/admin/media/"
        <Location "/media/">
                SetHandler None
        </Location>

        <Directory /opt/graphite/conf/>
                Order deny,allow
                Allow from all
        </Directory>

</VirtualHost>
EOF
```

```
chown -R apache:apache /opt/graphite/storage/
/etc/init.d/httpd restart
```

```
cat > /etc/init.d/carbon-cache <<\EOF
#!/bin/bash
#
# This is used to start/stop the carbon-cache daemon

# chkconfig: - 99 01
# description: Starts the carbon-cache daemon

# Source function library.
. /etc/init.d/functions

RETVAL=0
prog="carbon-cache"

start_relay () {
    /usr/bin/python /opt/graphite/bin/carbon-relay.py start
        RETVAL=$?
        [ $RETVAL -eq 0 ] && success || failure
        echo
        return $RETVAL
}

start_cache () {
     /usr/bin/python /opt/graphite/bin/carbon-cache.py start
        RETVAL=$?
        [ $RETVAL -eq 0 ] && success || failure
        echo
        return $RETVAL
}

stop_relay () {
    /usr/bin/python /opt/graphite/bin/carbon-relay.py stop
        RETVAL=$?
        [ $RETVAL -eq 0 ] && success || failure
        echo
        return $RETVAL
}

stop_cache () {
          /usr/bin/python /opt/graphite/bin/carbon-cache.py stop
        RETVAL=$?
        [ $RETVAL -eq 0 ] && success || failure
        echo
        return $RETVAL
}

# See how we were called.
case "$1" in
  start)
    #start_relay
    start_cache
        ;;
  stop)
    #stop_relay
    stop_cache
        ;;
  restart)
    #stop_relay
    stop_cache
    #start_relay
    start_cache
    ;;

  *)
        echo $"Usage: $0 {start|stop}"
        exit 2
        ;;
esac

EOF
chmod +x /etc/init.d/carbon-cache
```

```
service memcached start
service carbon-cache start
service httpd start
```
@kgadek
Copy link

kgadek commented Jun 3, 2014

Thanks so much for this!

Using CentOS 6.5 here and I had to do one step more -- change "client authentication" for PostrgreSQL (default was ident, this needs to be md5).
I forked your gist and applied a change ( https://gist.github.com/kgadek/5d12511a4825d2489fcd/revisions ). Feel free to pull it back :)

--edit--
Introducing further changes (like: clean install of CentOS and hostname -f not working…)

@ashrithr
Copy link
Author

@kgadek thanks for the updates will pull it back and merge.

@eran132
Copy link

eran132 commented Sep 11, 2014

Why did you comment out this line?

bitmap bitmap-fonts python-devel glibc-devel gcc-c++ openssl-devel python-zope-interface httpd memcached mod_wsgi

@poonkuzhalik
Copy link

Thanks so much.
Detailed procedure to get everything working in the first shot

@poonkuzhalik
Copy link

I had a problem in getting the graph in graphite. On analysis, I found out that whisper database was not getting populated with the value. Digging deep, I understood there could be possible mismatch with the data interval configured in the collectd and whisper.

Did the following

  1. Configured the /etc/collectd.conf to say interval has 60 seconds [Add the line Interval 60 in the file]
  2. Configure the graphite schema [/opt/graphite/conf/storage-schemas.conf]
    [carbon]
    pattern = ^carbon.
    retentions = 60:90d

Rebuild the RRD and whisper database by removing all the *.rrd and *.wsp files and doing the service restart

  1. /etc/init.d/collectd restart
  2. service carbon-cache restart
    3 service httpd restart

@mrideout
Copy link

Thanks for writing this up!

Using CentOS 6.6, I had to make two changes:

  1. Remove the line that updates /etc/postgresql/9.*/main/pg_hba.conf (that file is actually located within the /var/lib/pgsql/data/ directory, and the rest of the procedure worked when omitting that step entirely).
  2. Restart PostgreSQL after the 'Modify PostgreSQL "Client Authentication" -- use md5' step.

Here's the fork:

https://gist.github.com/mrideout/af84092f6b97ab53fb37

Here are the two updates:

https://gist.github.com/mrideout/af84092f6b97ab53fb37/revisions

Feel free free to pull it back.

Matt

Copy link

ghost commented Feb 9, 2015

Any idea why the graphite browser would pull up in a browser, but everything below the nav bar is blank?

Specifically, I can log into graphite, but I can't edit/modify/create graphs. Existing graphs continue to collect data and update, since I pasted the image links into a separate noc page.

This is on CentOS 6.6

@gitbrad
Copy link

gitbrad commented Feb 23, 2015

I'm seeing a similar issue to what raysanders is describing.

@logkaa
Copy link

logkaa commented Mar 26, 2015

regarding the "Installation of Grafana", is that all? Any additional actions?

@ksalaheddine
Copy link

In Redhat 6 You should add :

service httpd stop
service postgresql stop
setsebool -P httpd_can_network_connect 1
service httpd start
service postgresql start

For this error : " could not connect to server: Permission denied " If Graphite-Web didn't work

@e8-preet
Copy link

e8-preet commented Jun 5, 2015

@s2deaths
Thanks for the fix

@cbr6
Copy link

cbr6 commented Dec 15, 2015

CentOS 6.5 - I was getting an error in the /etc/httpd/logs/graphite_error.log

[Tue Dec 15 16:08:54 2015] [error] [client 172.26.253.94] File "/usr/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 177, in _cursor
[Tue Dec 15 16:08:54 2015] [error] [client 172.26.253.94] self.connection = Database.connect(**conn_params)
[Tue Dec 15 16:08:54 2015] [error] [client 172.26.253.94] OperationalError: could not connect to server: Permission denied
[Tue Dec 15 16:08:54 2015] [error] [client 172.26.253.94] \tIs the server running on host "localhost" and accepting
[Tue Dec 15 16:08:54 2015] [error] [client 172.26.253.94] \tTCP/IP connections on port 5432?

Fixed with "setsebool -P httpd_can_network_connect_db on"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment