Installing Graphite: ------------------- **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](https://graphite.readthedocs.org/en/1.0/tools.html) out there that know how to send data to graphite. Even though it often requires a little code, [sending data](https://graphite.readthedocs.org/en/1.0/feeding-carbon.html) 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: ========== **Install Required repo**: Redhat: ``` curl -o epel.rpm -L http://download.fedoraproject.org/pub/epel/6/$(arch)/epel-release-6-8.noarch.rpm rpm -ivh epel.rpm yum install pycairo Django14 python-ldap python-memcached python-sqlite2 bitmap bitmap-fonts-compat \ python-devel python-crypto pyOpenSSL gcc python-zope-filesystem python-zope-interface git gcc-c++ \ zlib-static MySQL-python python-txamqp python-setuptools python-psycopg2 mod_wsgi ``` Ubuntu: ``` apt-get install python-cairo python-twisted python-django python-django-tagging python-ldap \ python-memcache python-sqlite python-simplejson python-txamqp ca-certificates ``` Download and extract packages: ``` carbon_version="0.9.12" whisper_version="0.9.12" graphite_web_version="0.9.12" build_dir="/opt" cd ${build_dir} curl -s -L https://github.com/graphite-project/carbon/archive/${carbon_version}.tar.gz | tar xz curl -s -L https://github.com/graphite-project/whisper/archive/${whisper_version}.tar.gz | tar xz curl -s -L https://github.com/graphite-project/graphite-web/archive/${graphite_web_version}.tar.gz | tar xz easy_install django-tagging==0.3.1 easy_install twisted==11.1.0 easy_install txamqp==0.4 ``` Install webapp (this requires djando-tagging) ``` cd /opt/graphite-web-0.9.12 python setup.py install # subscribe to untar webapp ``` Install carbon (this requires twisted) ``` cd /opt/carbon-0.9.12 python setup.py install ``` Install whisper (this requires twisted) ``` cd /opt/whisper-0.9.12 python setup.py install ``` Configuring: =========== Install postgres as a backend for graphite: ``` yum -y install postgresql postgresql-server postgresql-devel 1. Yum Install PG9.4 2. wget http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-redhat94-9.4-1.noarch.rpm 3. yum install pgdg-redhat94-9.4-1.noarch.rpm 4. yum install postgresql94-server 5. service postgresql-9.4 initdb 6. chkconfig postgresql-9.4 on ``` Configure postgres to allow graphite user: ``` service postgresql initdb grep "listen_addresses = '0.0.0.0'" /var/lib/pgsql/data/postgresql.conf if [[ $? -ne 0 ]]; then echo "listen_addresses = '0.0.0.0'" >> /var/lib/pgsql/data/postgresql.conf fi service postgresql start sudo -u postgres psql template1 < /opt/graphite/webapp/graphite/local_settings.py < /var/lib/pgsql/data/pg_hba.conf < /opt/graphite/conf/graphite.wsgi < /opt/graphite/conf/storage-schemas.conf < /opt/graphite/conf/carbon.conf < /opt/graphite/conf/storage-aggregation.conf < 2&>1 /dev/null); then cat > /etc/hosts < /etc/httpd/conf.d/graphite.conf < LoadModule wsgi_module modules/mod_wsgi.so WSGISocketPrefix run/wsgi 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/ SetHandler None Alias /media/ "@DJANGO_ROOT@/contrib/admin/media/" SetHandler None Order deny,allow Allow from all EOF ``` ``` 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 sleep 5 #start_relay start_cache ;; *) echo $"Usage: $0 {start|stop}" exit 2 ;; esac EOF chmod +x /etc/init.d/carbon-cache ``` ``` service carbon-cache start service httpd start ``` Install collectd: ================ ``` yum install -y rrdtool rrdtool-devel perl rrdtool-perl libgcrypt-devel gcc make gcc-c++ perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-ExtUtils-Embed cd /opt curl -s -L http://collectd.org/files/collectd-5.4.0.tar.bz2 | tar jx cd collectd-5.4.0 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --libdir=/usr/lib --mandir=/usr/share/man --enable-cpu --enable-curl --enable-df --enable-exec --enable-load --enable-logfile --enable-memory --enable-network --enable-nginx --enable-syslog --enable-rrdtool --enable-uptime --enable-write_graphite make make install cp contrib/redhat/init.d-collectd /etc/init.d/collectd chmod 755 /etc/init.d/collectd chown root:root /etc/init.d/collectd /etc/init.d/collectd start chkconfig collectd on ``` Creation of collectd packages so that , if you have internal repos you could install it via package manager. ``` # Install tools required to build the rpms yum install -y rpm-build yum-utils rpmdevtools # Install EPEL rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm # Go to /tmp to get and extract collectd source base cd /tmp wget -c http://collectd.org/files/collectd-5.5.0.tar.bz2 # Extract source tar xvf collectd-5.5.0.tar.bz2 # Create build directory mkdir -p /root/rpmbuild/SOURCES/ # Copy sources in build directory cp collectd-5.5.0.tar.bz2 /root/rpmbuild/SOURCES/ # Install dependencies of the spec file yum-builddep -y collectd-5.5.0/contrib/redhat/collectd.spec # Create RPMS rpmbuild -bb collectd-5.5.0/contrib/redhat/collectd.spec # Copy RPMs back to the host cp -rv /root/rpmbuild/RPMS/ /root ``` Configure collectd to write system metrics to graphite by editing `/etc/collectd.conf` and adding the following lines: ``` LoadPlugin syslog LoadPlugin "logfile" LogLevel "info" File "/var/log/collectd.log" Timestamp true LoadPlugin cpu LoadPlugin interface LoadPlugin load LoadPlugin memory LoadPlugin rrdtool LoadPlugin write_graphite Host "127.0.0.1" Port "2003" Prefix "collectd." #Postfix "" Protocol "tcp" EscapeCharacter "_" SeparateInstances true StoreRates false AlwaysAppendDS false ``` Restart collectd to start sending metrics to graphite ``` /etc/init.d/collectd restart ``` Installing Grafana 2.10 ================== Grafana is a custom dashboard for graphite. ``` sudo yum install https://grafanarel.s3.amazonaws.com/builds/grafana-2.1.0-1.x86_64.rpm sudo service grafana-server start ``` Configure grafana with httpd: ``` cat > /etc/httpd/conf.d/grafana.conf < ServerName graphana.host.com ServerAlias grafana.host.com ProxyPass / http://localhost:3000/