How to monitor Linux servers with SNMP and Cacti

SNMP (or Simple Network Management Protocol) is used to gather data on what is going on within a device, such as load, hard disk states, bandwidth. These data are used by network monitoring tools such as Cacti to generate graphs for monitoring purposes.

In a typical deployment of Cacti and SNMP, there will be one or more SNMP-enabled devices, and a separate monitoring server where Cacti collects SNMP feeds from those devices. Please keep in mind that all the devices that need to be monitored must be SNMP enabled. In this tutorial, we will be configuring Cacti and SNMP on the same Linux server for demonstration purpose.

Configure SNMP on Debian or Ubuntu

To install SNMP agent (snmpd) on a Debian-based system, run the following command.

root@server:~# apt-get install snmpd

Then edit its configuration like the following.

root@server:~# vim /etc/snmp/snmpd.conf
# this will make snmpd listen on all interfaces
agentAddress  udp:161

# a read only community 'myCommunity' and the source network is defined
rocommunity myCommunity

sysLocation    Earth
sysContact     email@domain.tld

After editing the config file, restart snmpd.

root@server:~# service snmpd restart

Configure SNMP on CentOS or RHEL

To install SNMP tools and libraries, run the following command.

root@server:~# sudo yum install net-snmp

Then edit an SNMP config file like the following.

root@server:~# vim /etc/snmp/snmpd.conf
# A user 'myUser' is being defined with the community string 'myCommunity' and source network
com2sec myUser myCommunity

# myUser is added into the group 'myGroup' and the permission of the group is defined
group    myGroup    v1        myUser
group    myGroup    v2c        myUser
view all included .1
access myGroup    ""    any    noauth     exact    all    all    none
root@server:~# service snmpd restart
root@server:~# chkconfig snmpd on

Restart snmpd service, and add it to startup service list.

Testing SNMP

SNMP can be tested by running the snmpwalk command. If SNMP has been successfully configured, this command will generate a ton of output.

root@server:~# snmpwalk -c myCommunity -v1
iso. = STRING: "Linux mrtg 3.5.0-17-generic #28-Ubuntu SMP Tue Oct 9 19:31:23 UTC 2012 x86_64"
iso. = OID: iso.
iso. = Timeticks: (2097) 0:00:20.97


iso. = Gauge32: 1440
iso. = Counter32: 1
iso. = Counter32: 0
iso. = Timeticks: (1) 0:00:00.01
iso. = Hex-STRING: 07 DD 0B 12 00 39 27 00 2B 06 00 

Configure Cacti with SNMP

In this tutorial, we are setting up both Cacti and SNMP on the same Linux server. So go ahead and install Cacti on your Linux server on which SNMP was just configured.

After installation, Cacti web interface can be accessed using the link "", of course, in your case, the IP address of your server.

The paths during Cacti installation are usually correct. But they can be double checked if necessary.

During the first-time installation, the default username and password for Cacti are "admin" and "admin". You will be forced to change the password after first login.

Add and Manage Devices to Cacti

Cacti will poll devices based on SNMP string that was configured earlier. In this tutorial, we will add only the local server where SNMP is already enabled.

To add devices, we login as admin and go to console in the Cacti admin panel. We click Console > Devices.

There may already be a device named 'localhost'. We do not need it as we will create fresh graphs. We can delete this device from the list. We add a new device by using the 'add' button.

Next, we set the device parameters.

Now that the device has been added, we specify the graph templates that we want to create. This section can be found in the bottom section of the page.

And then we proceed to creating the graphs.

Here, we create graphs for load average, RAM and hard disk, processor.

Interface Graphs and 64-bit Counters

By default, Cacti uses 32-bit counters in SNMP queries. 32-bit counters are sufficient for most bandwidth graphs, but they do not work correctly for graphs greater than 100 Mbps. If it is known that the bandwidth will exceed more than 100 Mbps, it is always advisable to use 64-bit counters. Using 64-bit counters is not hard at all.

Note: It takes around 15 minutes for Cacti to populate new graphs. There are not alternatives to being patient.

Creating Graph Trees

These snapshots illustrate how to create graph trees and how to add graph to those trees.

We can verify the graph in the graph tree.

User Management

Finally, we create a user with view permission to only the graph that we have created. Cacti has built in user management system, and it is highly customizable.

After completing these steps, we can log in with the user 'user1' and verify that only this user is able to view the graph.

And thus we have deployed a Cacti server in the network monitoring system. Cacti servers are stable, and can deal with tons of graphs without any problems.

Hope this helps.

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Sarmed Rahman is an IT professional based in Australia. He writes tutorial articles on technology every now and then from a belief that knowledge grows through sharing. During his free time, he loves gaming and spending time with his friends.

16 thoughts on “How to monitor Linux servers with SNMP and Cacti

  1. Interface traffic is easy. Still working out how go get it to monitor CPU, load average, ntp drift and available disk space.

    Also, if you can't get snmpd to respond with data, and you used snmpconf to configure it, be aware that snmpconf on CentOS doesn't know the proper location for snmpd.conf.

    1. Copy the snmpd.conf file it generated to /etc/snmp/snmpd.conf

    2. Fix selinux security context with: fixfiles restore /etc/snmp/snmpd.conf

    3. Service snmpd restart

    • You could try the following templates provided with cacti. It can be found in the 'Associated Data Queries' section.

      Disk/RAM usage: SNMP - Get Mounted Partitions
      Processor: SNMP - Get Processor Information (Note: does not work with Cisco devices)
      Load Average: Unix - Load Average (Under 'Associated Graph Templates' section)

      At the end of the day, you could create your own templates or use 3rd party plugins if needed.

      And thank you for the tip on SELinux.

  2. 90 zeros in a row to 'pretend' to have a tree structure :) cacti is not a monitoring system, it can only show you trends. If you want trending and monitoring you might want to try pnp4nagios.

    • Personally, I prefer the cacti+nagios+smokeping trio, which serves most of the needs for any service provider network.

  3. I've used Cacti for a few years. The plug-ins that are available are what make it really shine on my network. Especially Nectar, Discover, Monitor, and the Network Weathermap. It is a great project. With some knowledge about MIBs and XML, you can create your own graph host and graph templates for almost anything reported by SNMP. And with displaying the data in any way, it may be useful for your analysis.

  4. Hello, this is cool.

    but i want do it over the internet. can i do the snmp protocol over ssh?

    Serveur cacti RouteurInternetSomewhereServeur Web>

    What do u think please?

    • You can pull data using SNMP over the Internet. However, I am not sure about polling over SSH.

      SNMP v1, v2 are cleartext, so they should be used using private IP addresses.
      SNMP v3 is a bit harder to configure, but it provides encryption (MD5, DES). It is recommended for polling over the Internet.

      Hope this helps.

Leave a comment

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