Cacti on a Raspberry Pi (and a Synology NAS)


Nothing’s as great to look at as traffic stats of your home network.

Well, not really, but still here’s the gist of how you can take a Raspberry Pi, hook it up to your network, and set up cacti on it to monitor your devices. I’ll even throw in some SNMP goodness for Synology DiskStations in the next post.

Actually, most of this post is a shameless copy from n00badmin (http://n00blab.com/cacti-pi/), with the SQL part moved from the Raspberry Pi to my Synology NAS, but more on that below. Make sure to visit his site on more Pi/cacti optimization goodness.

For those of you not in the know, cacti is a web front-end to rrdtool, which you can use to track any time-series data (network traffic, disk usage, CPU load, but also outside temperature, your power meter readings, or even stock market data) and draw pretty graphs like the one shown above. Further, a Raspberry Pi is a small form-factor computer designed by the Raspberry Pi foundation, mainly intended for educational use, but more than capable enough for running a webserver (provided you don’t want to serve too large an audience) or cacti, for that matter.

DISCLAIMER: As always, I take no responsibility for anything that happens because you follow these instructions – but you probably knew that. This is by no means a secure, production-level setup, but just me playing with stuff. Especially, you should take care not to enable SNMP access outside of your network, as Bad Things Can Happen(TM).

What you need

Setting up Raspbian on the Raspberry Pi

Raspbian is a Debian-derived linux distribution for the Pi, with the major benefit that it does include apt-get, so installing additional packages is a breeze. You can follow the official guide at raspberrypi.org to install Raspbian, but here’s the short version:

  1. Format your SD card (4GB or more) as exFAT (you can use sdcard.org’s SD Card Formatter for that)
  2. Extract the contents of the NOOBS package onto the SD card
  3. Hook up a monitor, mouse, and keyboard to your Raspberry Pi, stick in the SD card, network connection, and plug in the power
  4. Choose to install Raspbian from the menu, and follow the on-screen instructions
  5. Complete the Raspbian setup and login (username’s „pi“, you set the password during installation)

Installing cacti

The actual installation is covered pretty well by n00badmin (http://n00blab.com/cacti-pi/). Because I already have a MySQL server running as part of the official packages on my Synology NAS, I skipped the MySQL installation and configuration part and used phpMyAdmin on the Synology instead.

So, if you want to host your MySQL server on your Synology NAS as well, do this:






Then, on your Raspberry Pi, do this (taken directly from n00blab.com, all credit to him):

apt-get update
apt-get install apache2
apt-get install php5
apt-get install php5-mysql php5-snmp rrdtool snmp snmpd 

Run the following command to confirm required php modules are present:

php -m

mysql (For configuration, see note below)
SNMP (For configuration, see note below)
LDAP (Required only when using LDAP authentication)
GD (Required only for some Plugins)

Edit php.ini to point to extension directory found in:

cd /usr/lib/php5/

The name of the extension directory which will likely be a number/date ie 20090626 or 20100525+lfs depending on your distro. My Raspberry Pi had the following:

vi /etc/php5/apache2/php.ini

extension_dir = /usr/lib/php5/20100525+lfs/

Edit Apache2.conf to point to php.conf:

vi /etc/apache2/apache2.conf

Include conf.d/*.conf

Create php.conf:

cd /etc/apache2/conf.d/
vi php.conf

Paste this in the file:

# PHP is an HTML-embedded scripting language which attempts to make
# it easy for developers to write dynamically generated webpages.
LoadModule php5_module modules/libphp5.so
# Cause the PHP interpreter to handle files with a .php extension.
AddHandler php5-script .php
AddType text/html .php
# Add index.php to the list of files that will be served as
# directory indexes.
DirectoryIndex index.php

Download Cacti:

cd /var/www/
wget http://www.cacti.net/downloads/cacti-0.8.8b.tar.gz

Untar Cacti:

tar xzvf cacti-0.8.8b.tar.gz

Rename the directory for uniformity:

mv cacti-0.8.8b cacti

Drop into the Cacti directory:

cd cacti

Edit include/config.php and specify the database type, name, host, user and password for your Cacti configuration.

vi include/config.php

$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "<your_synology's IP>";
$database_username = "cacti";
$database_password = "<whatever you set above>";

Set the appropriate permissions on cacti’s directories for graph/log generation. You should execute these commands from inside cacti’s directory to change the permissions.

shell> chown -R www-data rra/ log/

Add a line to your crontab file:

vi /etc/crontab

*/5 * * * * www-data php /var/www/cacti/poller.php > /dev/null 2>&1

Restart apache:

service apache2 restart

Point your web browser to http://your-server/cacti/. Use ifconfig if you are unsure of your Raspberry Pi’s IP address

Log in the with a username/password of admin. You will be required to change this password immediately. Make sure all of the path variables show found on the following screen.

At this point you should have an operational install up and running with the default localhost being monitored for basic system info. In order to gather more info including processor and interface traffic edit the following:

cd /etc/snmp

cp snmpd.conf snmpd.conf_orig

vi snmpd.conf

Uncomment and edit the following:

#rocommunity secret


rocommunity cacti

Then restart snmpd

service snmpd restart


[…] ennonymous.de: Cacti on a Raspberry Pi (and a Synology NAS) […]

Posted by Synology: Useful Resources | Marc Lognoul on 17 November 2015 @ 6pm

Thx for the walkthrough! Just a question. When i get to the part that cacti should be up and running on apache. i go to the ipadres/cacti and apache tells me it cannot find the site. So i moved the cacti install to var/www/html/ and then it gives me litterally nothing. I can’t seem to find the path is still have to redirect (i have done the crontab). Could you point me in the right direction?

Thx in advance!

Posted by Arjan on 16 Juli 2016 @ 5am

Leave a Comment