Thursday, May 22, 2014

Install and config Graphite on Debian/Ubuntu

Install graphite server using python-pip


apt-get install gcc python-dev python-pip

sudo pip install https://github.com/graphite-project/ceres/tarball/master
sudo pip install whisper
sudo pip install carbon
sudo pip install graphite-web

cd /opt/graphite/conf
sudo cp carbon.conf.example carbon.conf
sudo cp storage-schemas.conf.example storage-schemas.conf
sudo cp graphite.wsgi.example graphite.wsgi


===========================================

Run carbon service and test

===========================================

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

if you get something like Python Error - ImportError: cannot import name daemonize
take a look at: Can't Start Carbon - 12.04 - Python Error - ImportError: cannot import name daemonize
try:
sudo pip install 'Twisted<12.0'

check if the port of carbon service is opened:
netstat -naep | grep 2003

test:
perl -e '$ts = time(); for (1..1000) { printf "foo.bar %d %d\n", int(rand(10000)), $ts - 90 * $_ }' \ | nc -c localhost 2003


===========================================

Run Graphite web UI (apache2 with mod_python, mod_wsgi)

===========================================

sudo apt-get install apache2 libapache2-mod-python libapache2-mod-wsgi

sudo chown -R www-data:www-data /opt/graphite/storage/

sudo mv /etc/apache2/sites-available/default /etc/apache2/sites-available/default.bak
sudo cp /opt/graphite/examples/example-graphite-vhost.conf /etc/apache2/sites-available/default
sudo mkdir /etc/httpd
sudo mkdir /etc/httpd/wsgi

cd /opt/graphite/webapp/graphite/
sudo cp local_settings.py.example local_settings.py

restart apache2
sudo service apache2 restart


===========================================

Initialize database after installed apache2

===========================================

sudo apt-get install python-django
sudo pip install django-tagging==0.3.1

cd /opt/graphite/webapp/graphite/
sudo python manage.py syncdb
Username: root
Password: xxx
E-mail: info@fxlive.de

Edit
/opt/graphite/webapp/graphite/local_settings.py
add:
SECRET_KEY
TIME_ZONE = 'Europe/Berlin'
LOG_RENDERING_PERFORMANCE = True
LOG_CACHE_PERFORMANCE = True
LOG_METRIC_ACCESS = True


===========================================

Troubleshooting

===========================================

1) Edit the following file:
/etc/apache2/sites-available/default

Make sure that the configuration for WSGISocketPrefix is set as follows:
WSGISocketPrefix /var/run/apache2/wsgi

Otherwise, you will get the following error:

    [Tue Jun 19 13:21:28 2012] [error] [client 192.168.xxx.xxx] (2)No such file or directory: mod_wsgi (pid=19506): Unable to connect to WSGI daemon process 'graphite' on '/etc/apache2/run/wsgi.19365.1.1.sock' after multiple attempts.


2) if you changed the VirtualHost post, do not forget to add this port in
/etc/apache2/ports.conf
add something like this:
NameVirtualHost *:8000
Listen 8000


3) if you can not see the images, get something like this:
ViewDoesNotExist: Could not import graphite.render.views. Error was: No module named cairo

you need install:
sudo apt-get install python-cairo-dev


4) watch the logs if something still not working right:
cd /opt/graphite/storage/log/webapp
find . -name '*.log' | xargs tail -F

5) location of graphite's whisper database (RDD storage)
/opt/graphite/storage/whisper


===========================================

example: storage-schemas.conf

===========================================

[stats_1day]
pattern = ^stats_1day\.
retentions = 1d:1y

[stats_1hour]
pattern = ^stats_1hour\.
retentions = 1h:90d


===========================================

example: /etc/apache2/sites-available/default

===========================================

<IfModule !wsgi_module.c>
    LoadModule wsgi_module modules/mod_wsgi.so
</IfModule>

WSGISocketPrefix /var/run/apache2/wsgi

<VirtualHost *:8000>
        ServerName graphite
        DocumentRoot "/opt/graphite/webapp"
        ErrorLog /opt/graphite/storage/log/webapp/error.log
        CustomLog /opt/graphite/storage/log/webapp/access.log common

        # enable XORS (Cross-origin resource sharing), see below
        Header set Access-Control-Allow-Origin "*"

        # I've found that an equal number of processes & threads tends
        # to show the best performance for Graphite (ymmv).
        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}

        # XXX You will need to create this file! There is a graphite.wsgi.example
        # file in this directory that you can safely use, just copy it to graphite.wgsi
        WSGIScriptAlias / /opt/graphite/conf/graphite.wsgi

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

        # XXX In order for the django admin site media to work you
        # must change @DJANGO_ROOT@ to be the path to your django
        # installation, which is probably something like:
        # /usr/lib/python2.6/site-packages/django
        Alias /media/ "@DJANGO_ROOT@/contrib/admin/media/"
        <Location "/media/">
                SetHandler None
        </Location>

        # The graphite.wsgi file has to be accessible by apache. It won't
        # be visible to clients because of the DocumentRoot though.
        <Directory /opt/graphite/conf/>
                Order deny,allow
                Allow from all
        </Directory>

</VirtualHost>


you may want to enable XORS (Cross-origin resource sharing) or cross site scripting or whatever~

you should add this line
Header set Access-Control-Allow-Origin "*"
in to
/etc/apache2/sites-available/default

and then restart apache2


===========================================

bugfix

===========================================

there is a small bug in Graphite's Dashboard JS, take a look this post:
http://www.abcn.net/2014/01/graphites-dashboard-set-auto-hide-navbar.html


2 comments:

  1. show loaded modules:

    apachectl -t -D DUMP_MODULES

    ReplyDelete
  2. It's very useful article with inforamtive and insightful content and i had good experience with this information. We, at the CRS info solutions ,help candidates in acquiring certificates, master interview questions, and prepare brilliant resumes.Go through some helpful and rich content Salesforce Admin syllabus from learn in real time team. This Salesforce Development syllabus is 100% practical and highly worth reading. Recently i have gone through Salesforce Development syllabus and Salesforce Admin syllabus which includes Salesforce training in USA so practically designed.

    ReplyDelete

© Chutium / Teng Qiu @ ABC Netz Group