Installing Graphite on Debian Stretch

Getting Graphite Running

After having installed Icinga2, IcingaWeb and IcingaDirector I decided I wanted some better pretty pictures and graphs.

I have Grafana installed via HomeAssistant and so decided the next point was to install Graphite and get some data into it and then to Grafana for display.

It was not as easy as expected.

First port of call to see how to do this was https://graphite.readthedocs.io/en/latest/index.html which is IMHO not that easy to follow – it is all there but the actual steps are not that clear and initially I got stuck at Initial Configuration and the Nginx + uWSGI step and gave up and deleted everything including the virtual environment I had created.

I then decided to start again and read the dependencies a bit more carefully and also looked here https://gist.github.com/tristanbes/4046457 and here https://arpitbhayani.me/blogs/setting-up-graphite-using-nginx-on-ubuntu.

So I started again….

  • No virtual environment
  • Python3
  • Now the dependencies ….
    • Django (I had heard of this but did not know what it was). The tutorial here is great …. https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html and I followed this and got the sample app running. Main problems were getting the user and group www-data:www-data the right permissions.
    • I also tried to install django-tagging using pip3 and found it was already there as were these dependencies – putz and scandir
    • I tried to install fontconfig using pip3 and it failed and with a bit of googling found out this was a apt install apt-get install -y fontconfig. This was also up to date.
  • Then back to the instructions here https://graphite.readthedocs.io/en/latest/index.html and decided on default layout without a virtual environment.
  • Checked with development headers – all OK now. apt-get install python-dev libcairo2-dev libffi-dev build-essential
  • Installed packages
    • export PYTHONPATH=”/opt/graphite/lib/:/opt/graphite/webapp/”
    • pip install –no-binary=:all: https://github.com/graphite-project/whisper/tarball/master
    • pip install –no-binary=:all: https://github.com/graphite-project/carbon/tarball/master
    • pip install –no-binary=:all: https://github.com/graphite-project/graphite-web/tarball/master
  • From the link a arpitbhayani.me I decided to use Postgres as the database and followed his config instructions and so needed to sudo pip3 install psycopg2 as psycopg2 is a dependency for using Postgres.
  • Then did the Webapp Database setup – this is why Django was needed to be installed BEFORE this step – i.e. dependency
  • Then the steps in Nginx + uWSGI were followed… with a few changes
    • I decided to use a socket for NGINX and so the graphite.ini was different (socket = /opt/graphite/webapp/graphite/graphite.sock) and as I have no virtual environment the virtualenv setting not needed.
  • The Nginx conf file is as follows….
# /etc/nginx/sites-available/graphite.conf
upstream graphite {
    #server unix:///path/to/your/mysite/mysite.sock; # for a file socket
    server unix:///opt/graphite/webapp/graphite/graphite.sock; # for a file socket

}

server {
    listen 8080;
   # the domain name it will serve for
    server_name <ip-address>; # substitute your machine's IP address or FQDN
    charset     utf-8;

    location /static/ {
        alias /opt/graphite/webapp/content/;
    }

    location / {
        include /opt/graphite/conf/uwsgi_params;
        uwsgi_pass graphite;
    }
}

Configuring Carbon

  • Firstly copy some files from /opt/graphite/conf for editing (now only at line 18 and 19 in this link https://gist.github.com/tristanbes/4046457)
    • sudo cp carbon.conf.example carbon.conf
    • sudo cp storage-schemas.conf.example storage-schemas.conf
  • and now do lines 21-56 in the link from tristanbes to set up storage-schemas.conf and storage-aggregation.conf
  • Next following the instructions on editing the carbon.conf in the main graphite documentation including changing the cache ports 2003 to 2013 and 2003 to 2014 in cache section and the Destination setting in relay section
  • Now set up a system service for carbon-cache

[Unit]
Description=Graphite Carbon Cache
After=network.target

[Service]
Type=forking
StandardOutput=syslog
StandardError=syslog
ExecStart=/opt/graphite/bin/carbon-cache.py –config=/opt/graphite/conf/carbon.conf –pidfile=/var/run/carbon-cache.pid start
ExecReload=/bin/kill -USR1 $MAINPID
PIDFile=/var/run/carbon-cache.pid

[Install]
WantedBy=multi-user.target

  • enable the service (sudo systemctl enable carbon-cache.service)
  • and start it.
  • Try sending some into port 2013.
  • e.g.
echo "test.count 9 `date +%s`" | nc -q0 127.0.0.1 2003;

This will add one data metric of value 9 in system. Lets add some more data; this time wee loop through values

for i in 4 6 8 16 2; do echo "test.count $i `date +%s`" | nc -q0 127.0.0.1 2003; sleep 6; done
  • and you should be able to see data in Graphite like this
test.count graph in Graphite

Leave a Reply

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