Monitoring Linux and Windows hosts with SNMP and Cacti



Monitoring Linux and Windows hosts with SNMP and Cacti

Download Video (989 KB)

SNMP is a communication specification that defines how management information is exchanged between network management applications and management agents.

Cacti is a resource monitoring software. It uses RRDtool to store data and the data is used create graphs. It also comes with fast poller to collect data from different resources simultaneously and has many user management features. The interface and management is very userfriendly that even a layman can get it working with less effort.

This article is about how to monitor Linux and Windows hosts with SNMP (2c version) and Cacti.

Setup SNMP daemon on Gentoo Linux host. First, enable support for graphing I/O statistics – enable diskio MIB module for package net-analyzer/net-snmp:

echo net-analyzer/net-snmp diskio >> /etc/portage/package.use

Install SNMP daemon:

emerge -av net-snmp

Open config file /etc/conf.d/snmpd and make SNMP daemon to listen on all interfaces by removing the ip 127.0.0.1 from config file. For this, search in config for the line:

SNMPD_FLAGS="${SNMPD_FLAGS} -Lsd -Lf /dev/null 127.0.0.1"

Download a pre-configured config file template, start the daemon and add it to runlevel default:

wget sysadmin.md/uploads/config/snmpd.conf -O /etc/snmp/snmpd.conf
/etc/init.d/snmpd start
rc-update add snmpd default

Test whether SNMP can read the system MIBs using the snmpwalk command:

snmpwalk -v 2c -c cacti_com 127.0.0.1 system

Setup SNMP service on Windows host by going to Start->Run and type:

appwiz.cpl @,2

This command will open Add/Remove Windows Components Wizard.

In list find Management and Monitoring Tools and click Details. In new window check Simple Network Management Protocol and press OK to select it. Press Next to begin installation of SNMP service.

To configure Windows SNMP service go to Start->Run and type:

services.msc

The above command will open System Services window. In window list find SNMP service and double-click on it. Go to Agent Tab, fill the Contact and Location boxes and check all Service checkboxes.

Finally, go to Security Tab and edit the Community name.

Optional: you can specify from what hosts your windows machine can accept SNMP packets.

To test the service read the system MIBs with snmpwalk command:

snmpwalk -v 2c -c cacti_com 172.16.50.179 system

Install Cacti. The below instructions is for Gentoo box:

emerge -av cacti
webapp-config -I -h localhost -d cacti-dir cacti 0.8.7b-r3

Next, create the new database for cacti and import default schema:

mysqladmin -p -u root create cacti_db
mysql -p cacti_db</var/www/localhost/htdocs/cacti-dir/cacti.sql

To access the database, create MySQL username and password for it:

mysql -p -u root mysql
mysql> GRANT ALL ON cacti_db.* TO cacti_user@localhost IDENTIFIED BY 'pa$$w0rd';
mysql> FLUSH PRIVILEGES;
mysql> quit

Edit Cacti config file and modify the MySQL user, password and database parameters. Alter config file located at /var/www/localhost/htdocs/cacti-dir/include/config.php:

$database_default = "cacti_db";
$database_hostname = "localhost";
$database_username = "cacti_user";
$database_password = "cacti db password";

Point your browser to http://ip.address/cacti-dir/

Next step, verify poller functionality:

/usr/bin/php /var/www/localhost/htdocs/cacti-dir/poller.php

Add the following poller line to /etc/crontab file:

*/5 * * * * apache /usr/bin/php /var/www/localhost/htdocs/cacti-dir/poller.php > /dev/null 2>&1

Also make sure that the user apache that runs poller.php has permission to create new files in cacti's rra/ and log/ directories:

cd /var/www/localhost/htdocs/cacti-dir
ls -ald rra log
chown -R apache:apache rra/ log/

To setup graphing Linux and Windows hosts, go to main Cacti page and login with following credentials:
Username: admin
Password: admin

Next, create devices that will be Linux and Windows hosts for monitoring by going to Management->Devices and select Add

Fill fields DescriptionHostname and SNMP Community. Don't forget to select Host Template and SNMP Version.

To create graphs for Windows and Linux hosts: navigate to Devices, click on new-created Devices and select Create Graphs for this Host.

Instructions in video are used to graph Logged in UsersProcessesDisk Space on partitionsVirtual MemoryPhysical MemoryInterface Statistics etc.

As optional feature, graphs could be added to default tree by going to Management->Graph Trees and selecting the Default Tree to edit them.

New-created graphs could be viewed by selecting the Graphs tab. In video are shown the graphs changes after 1 hour.