Cacti is a free network monitoring and graphing software. Cacti offers an easy-to-use web interface that is suitable for networks of all sizes. Cacti runs on Unix/Linux as well as Windows operating systems. In this article, we are going to install Cacti on Raspberry Pi, the popular single-board computer that took the world by storm. In this article, we briefly describe the procedure to install the Raspbian operating system on Raspberry Pi. We then install Cacti on Raspbian, and demonstrate how it can be used to graph interface traffic statistics from a Cisco router.

CCNA Training – Resources (Intense)

Cacti Overview

Cacti is an open source (read free) network monitoring and graphing tool. We are going to run Cacti on Raspbian, which is Linux, but the amazing thing is that you don’t have to be a Linux expert to install and use Cacti. With the intuitive web interface of Cacti, configuring and using Cacti is easy.

Cacti uses the Net-SNMP suite to collect data from monitored devices via the SNMP (simple network management protocol). Network infrastructure comprises a lot of different devices, including computers, servers, switches, routers, appliances, and even UPS. Cacti can monitor all these different devices as long as they support SNMP.

It uses the RRDtool (round-robin database tool) engine for to store data collected using SNMP, and to generate graphs.

Setting Up Raspberry Pi

We are using the topology shown in the following graphic:

We are using the Raspberry Pi 2 Model B, which is the second generation of Raspberry Pi. With a 900 MHz quad-core processor and 1 GB RAM, the Raspberry Pi 2 is packed with enough power to run Cacti.

Raspberry Pi 2 supports several operating systems, including Raspbian, Windows 10, and several others. Raspbian is a free operating system based on Linux and optimized for Raspberry Pi. You can install Raspbian easily, using the NOOBS (New Out Of the Box Software) installer. We are using NOOBS 1.4.2, which is the current version at the time of this writing. You can purchase a pre-installed NOOBS microSD card. Alternately, you can download NOOBS from here and use the instructions here, to build your NOOBS microSD card for Raspberry Pi. Connect a USB keyboard and an HDMI display to your Pi, and fire up the engines. The NOOBS installer will display a list of operating systems to choose from. Choose to install Raspbian, which is bundled with NOOBS. The installation of Raspbian is fully automated.

When the installation is complete, the Pi reboots directly into the Raspbian desktop environment. The default username and password are pi and raspberry, respectively.

Go to Menu > Accessories > Terminal to launch the terminal application. Use the sudo pico /etc/network/interfaces command to open the /etc/network/interfaces file, for editing. Replace the line iface eth0 inet manual with the following lines:

iface eth0 inet static
address 10.1.1.4
netmask 255.255.255.0
gateway 10.1.1.1

Save the interfaces file and exit the pico editor. You’d have to use IP configuration specific to your environment.

Bounce the eth0 interface, to bring the IP configuration into effect.

sduo ifdown eth0
sudo ifup eth0

Use the ifconfig command to verify the IP address assigned to the Ethernet interface of Raspberry Pi. By default, the SSH server is installed and running on Raspbian. Use the service ssh status command to verify the status of SSH server.

You can now disconnect the keyboard and display from your Pi, and run it headless. You can connect to the Raspberry Pi via SSH, which is the preferred method for the present (and most other) practical applications of the Pi. We are not going to need the Raspbian desktop environment.

Installing Cacti

Run the sudo apt-get update command. The apt-get update command downloads lists of packages from repositories and updates the downloaded lists with information on the newest versions of packages. The command does not actually install new versions of packages.

pi@raspberrypi:~$ sudo apt-get update
Get:1 http://mirrordirector.raspbian.org jessie InRelease [15.0 kB]
Get:2 http://mirrordirector.raspbian.org jessie/main armhf Packages [8,962 kB]
Get:3 http://archive.raspberrypi.org jessie InRelease [13.3 kB]
Get:4 http://archive.raspberrypi.org jessie/main Sources [26.2 kB]
Get:5 http://archive.raspberrypi.org jessie/ui Sources [5,197 B]
Get:6 http://archive.raspberrypi.org jessie/main armhf Packages [67.4 kB]
Get:7 http://archive.raspberrypi.org jessie/ui armhf Packages [7,639 B]
Get:8 http://mirrordirector.raspbian.org jessie/contrib armhf Packages [37.5 kB]
Get:9 http://mirrordirector.raspbian.org jessie/non-free armhf Packages [70.2 kB]
Get:10 http://mirrordirector.raspbian.org jessie/rpi armhf Packages [1,356 B]

Run the sudo apt-get upgrade command, which actually fetches new versions of packages known by way of the apt-get update command.

pi@raspberrypi:~$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
raspberrypi-ui-mods
The following packages will be upgraded:
bluej dhcpcd5 gir1.2-gdkpixbuf-2.0 gir1.2-gtk-3.0 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-common libgtk-3-0
libgtk-3-bin libgtk-3-common libsasl2-2 libsasl2-modules libsasl2-modules-db libvdpau1 ntp
python3-pgzero raspberrypi-net-mods raspi-config rc-gui unzip
19 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
Need to get 16.3 MB of archives.
After this operation, 1,235 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y

We are ready to install the real thing now, but Cacti has its prerequisites. It needs the following packages to function:

  1. RRDtool
  2. Net-SNMP
  3. MySQL
  4. PHP
  5. Apache (or another web server)

The good news is that you don’t have to separately install any of the prerequisite packages. The apt-get tool takes care of that, and makes it ridiculously easy to install Cacti. Just run the sudo apt-get install cacti command, and Cacti gets installed with all its dependencies.

pi@raspberrypi:~$ sudo apt-get install cacti
Reading package lists... Done
Building dependency tree
Reading state information... Done

The following extra packages will be installed:
apache2 apache2-bin apache2-data apache2-utils dbconfig-common libaio1 libapache2-mod-php5 libapr1
libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libdbd-mysql-perl libdbi-perl libdbi1
libhtml-template-perl libjs-jquery-cookie liblua5.1-0 libmysqlclient18 libonig2 libpci3
libperl4-corelibs-perl libperl5.20 libphp-adodb libqdbm14 librrd4 libsensors4 libsnmp-base libsnmp30
libterm-readkey-perl lsof mysql-client mysql-client-5.5 mysql-common mysql-server mysql-server-5.5
mysql-server-core-5.5 php5-cli php5-common php5-json php5-mysql php5-readline php5-snmp rrdtool snmp
ssl-cert

Suggested packages:
apache2-doc apache2-suexec-pristine apache2-suexec-custom php5-ldap moreutils php-pear libclone-perl
libmldbm-perl libnet-daemon-perl libsql-statement-perl libipc-sharedcache-perl php5-adodb lm-sensors
snmp-mibs-downloader mailx tinyca php5-user-cache librrds-perl openssl-blacklist

The following NEW packages will be installed:
apache2 apache2-bin apache2-data apache2-utils cacti dbconfig-common libaio1 libapache2-mod-php5
libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libdbd-mysql-perl libdbi-perl libdbi1
libhtml-template-perl libjs-jquery-cookie liblua5.1-0 libmysqlclient18 libonig2 libpci3
libperl4-corelibs-perl libperl5.20 libphp-adodb libqdbm14 librrd4 libsensors4 libsnmp-base libsnmp30
libterm-readkey-perl lsof mysql-client mysql-client-5.5 mysql-common mysql-server mysql-server-5.5
mysql-server-core-5.5 php5-cli php5-common php5-json php5-mysql php5-readline php5-snmp rrdtool snmp
ssl-cert
0 upgraded, 46 newly installed, 0 to remove and 1 not upgraded.
Need to get 22.6 MB of archives.
After this operation, 130 MB of additional disk space will be used.
Do you want to continue? [Y/n]Y

During Cacti installation:

  1. You will be asked to choose a new password for the MySQL root user. Choose cacti, or something else you can remember easily.
  2. You will see a warning that the include path for php has changed. Just press <Ok>.
  3. You will be asked to select the web server for which Cacti should be automatically configured. Choose apache2.
  4. You will also be asked to configure database for cacti with dbconfig-common. Press .
  5. You will then be asked to configure the password of the database’s administrative user. Choose cacti, or another password you can remember easily. Choose cacti also as the MySQL application password for Cacti.

Cacti will take a while to install because of the additional packages to be downloaded and installed.

Configuring Cisco Router

Cacti will use SNMP to talk to the Cisco router in our test environment. The router has two interfaces only, and we use just one of the two:

Router#show ip interface brief
Interface            IP-Address OK? Method Status Protocol
FastEthernet0/0        10.1.1.5 YES manual up up
FastEthernet0/1        unassigned YES DHCP administratively down down

In addition to IP addressing, you have to enable SNMP as shown below:

Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#snmp-server community public RO
Router(config)#end
Router#copy running-config startup-config
Destination filename [startup-config]?
Building configuration...
[OK]

We do not go into details of SNMP configuration. The point is to have a basic but functional system that you can build on later.

Using Cacti

Open a web browser and point it to http://10.1.1.4/cacti (replace 10.1.1.4 with the IP address assigned to your Pi). You should see a page that contains the following:

Press Next.

Confirm that New Install shows in the drop-down menu, and press Next.

Click Finish.

Enter admin as user name and admin as password, and press Login. You will be forced to change the password.

Choose cacti, or another password you can easily remember, and press Save.

Click Create devices.

You can see in the above screenshot that Localhost, which refers to the Pi, is already listed under Devices. Click Add at the top right of the page, and press Create at the bottom right of the page after filling details per the following screenshot:

You should notice that Cacti will fetch details of the Cisco router, as shown below:

Click Create Graphs for this Host, shown in blue.

We will graph FastEthernet0/0 because it is the Internet-facing interface of our router. Select the checkbox next to FastEthernet0/0 and press Create.

Go to Management > Graph Management in the left pane. You will see the following page:

Click My Cisco Router – Traffic – Fa0/0 to see the graph generated by Cacti. Please note that it may take a few minutes for the graph to be generated. If you don’t see a graph initially, just hang on and the graph will appear.

The ingress as well as the egress traffic is plotted. There’s a nice legend at the bottom to tell you what each color means. You can use the graph to determine link utilization, which is very useful for planning and troubleshooting.

You can use Cacti to monitor virtually any quantifiable aspect of a device, which supports SNMP. You can monitor CPU and memory usage, system temperature, fan status, and traffic statistics, to name a few. Cacti is a powerful tool that can be used to build an elaborate network monitoring system. Cacti is free, which makes it very attractive for startups and small to midsize companies.