Thursday, October 23, 2014

rrdcached is a daemon that receives updates to existing RRD files, accumulates them and, if enough have been received or a defined time has passed, writes the updates to the RRD file.
This can be very useful in a bigger Observium-instance as the number of polled interfaces grow and the number of RRD-files that will be updated each polling is increasing, soon each polling will be generating a lot of random writes to your storage.
rrdcached gives us the possibility to trade some of that IO for memory. This is can be very good deal for virtual machines or any server with a slower storage but a fair amount of memory.

This small guide is written and tested on Ubuntu Linux and I cant guarantee that it will work on any other distro.

1. Start by installing rrdcached using your favorite packet manager

# sudo apt-get update && sudo apt-get install rrdcached

2. The rrdcached daemon will be started automatically so we need to stop it.

# sudo service rrdcached stop

Stopping RRDtool data caching daemon: rrdcached.

3. Edit the start up options for the rrdcached daemon

# sudo nano /etc/default/rrdcached

Find the row in the configfile with #OPTS= and replace them with these options:

-z 1800 Delay writes by a random factor of up to 30 minutes (this should be equal to, or lower than, “-w”)

-f 3600 Flush all data every 3600s (1 hour)

-s set the group owner of the socket to www-data (this needs to be set before -l)

-l path to our socket that observium will talk to

-j path to journaling files

-F ALWAYS flush all updates to the RRD data files when the daemon is shut down

-b path to observium RRD-files

-B Only permit writes into the base directory specified in -b (and any sub-directories).

4. Now start rrdcached daemon again

# sudo service rrdcached start

5. Now here comes the big problem, as rrdached is started as root it will create the socket-file (/var/run/rrdcached.sock) with root permissions. But the webserver user need to be able to both read and write to this socket so we will need to change the owner to the webserver user (www-data in this case)

# sudo chown www-data:www-data /var/run/rrdcached.sock

This needs to be redone every time rrdcached is restarted as it will then recreate this file.This probably can be solved by manipulating the init-script or some other cleaver way, suggestions are highly appreciated! There are also flags in rrdcached for this (-m and -s) but I never got it to work, file owner was always root.
*NOTE* Step 5 no longer needed when using -s flag properly!

About

The Best Practice Blog is maintained by Markus Klock, a Cisco-certified computer networks consultant and Svante Boberg, a Senior server operations engineer.Here we write about computer networks, virtualization, security and other tech suff.