Cacti (monitoring tool based on snmp)
September 14th, 2009SNMP is a protocol to manage and monitor network devices. mrtg can capture the SNMP monitored data, analyze the data and generate the graphs. Previously, I used SNMP and mrtg to monitor my home server’s network traffic and CPU usage. However, mrtg is not quite powerful. RRDtool is a good substitution, but it’s very difficult to use. Therefore, I’m currently using cacti to help me to call RRDtool to generate the graphs. Cacti is actually a web based PHP software. So the installation path of cacti must be accessible by web server.
Environment: CentOS 5.3
Basic Setup:
Install some missing packages:
yum install intltool
yum install cairo-devel
yum install pango-devel
yum install net-snmp
yum install net-snmp-libs
yum install net-snmp-utils
Change some settings of snmpd:
vim /etc/snmp/snmpd.conf
Search:
com2sec notConfigUser default public
Replace:
com2sec notConfigUser 127.0.0.1 public
Give more permissions
Search:
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
Replace:
view systemview included .1.3.6.1.2.1
view systemview included .1.3.6.1.2.1.25.1.1
Search:
access notConfigGroup "" any noauth exact systemview none none
Replace:
access notConfigGroup "" any noauth exact all none none
Search:
#view all included .1 80
Replace (Remove comment):
view all included .1 80
Restart snmpd:
/etc/init.d/snmpd restart
turn on snmpd automatically when Linux starts:
ntsysv
Install RRDtool:
tar zxvf rrdtool-1.3.8.tar.gz
cd rrdtool-1.3.8
./configure --prefix=/usr/local/rrdtool
make
make install
Create cacti database:
mysql -u root -p
CREATE DATABASE cacti;
INSERT INTO mysql.user(Host,User,Password) VALUES ('localhost','cacti',password('cacti'));
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON cacti.* to cacti@localhost IDENTIFIED BY 'cacti';
\q
Install cacti:
tar zxvf cacti-0.8.7e.tar.gz
mv cacti-0.8.7e /home/admin/
/home/admin/cacti-0.8.7e /home/admin/cacti
Import cacti tables:
mysql -u cacti -pcacti cacti < /home/admin/cacti/cacti.sql
Edit cacti configurations:
vim /home/admin/cacti/include/config.php
Change to be like this:
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
$database_port = "3306";
Then, you can open your web browser to use cacti. Just simply follow the instruction to setup cacti. The following error may be shown as /usr/local/rrdtool/bin/rrdtool is not the default RRDTool installation path.
[NOT FOUND] RRDTool Binary Path: The path to the rrdtool binary.
Therefore, define the path of RRDTool installed previrously:
/usr/local/rrdtool/bin/rrdtool
The default username and password are admin
crontab configuration:
This step can update the cacti required information every five minutes.
Edit crontab file:
vim /etc/crontab
And add the following line at the end:
*/5 * * * * root /usr/local/php5/bin/php /home/admin/cacti/poller.php > /dev/null 2>&1
Where /usr/local/php5/bin/php is the binary execution of PHP.
More cacti configurations (monitoring network interface):
By default, cacti only shows the basic hardware configuration. But I also want it to display network interface information. Here is the configuration steps:
- Enable cacti SNMP v2 parsing:
In my experience, it does not work when I choose default value "Not In use".
Devices > [Description] > SNMP Version: Version 2 - Add Interface data source:
Devices > [Description] > Data Source List (Top Right) > Add (Top Right)
Choose:
Selected Data Template: Interface - Traffic
Host: [Description] 127.0.0.1
click Create button. - Select network interface:
New Graphs > Select interface (e.g. eth0) > Create
Static graphs generation:
If you want to show this graphs to public without login. You can generation the static pages and graphs.
- Create a directory first (e.g. /home/admin/public)
- Login Cacti and goto Console. Click Settings under Configuration part.
- Click Graph Export
- Input an associated path (i.e. /home/admin/public) in Export Directory (both local and ftp) field
- The graphs will be generated every five minutes by default.
Integrated lm_sensors to show the graph of CPU temperature:
** Before doing this part, please ensure the sensors driver is installed and lm_sensors is properly configured.
In this example, cacti is installed in /home/admin/cacti.
- Download cacti-netsnmp-lmsensors.0.8.tar.gz and extract it:
tar zxvf cacti-netsnmp-lmsensors.0.8.tar.gz - Copy scripts/ss_netsnmp_lmsensors.php to the /home/admin/cacti/scripts/ directory.
- Copy the XML files in resource/0.8.7/ to the /home/admin/cacti/resource/script_server/ directory
- Login to Cacti console and click Import Templates from the menu
- Upload the associated XML file (i.e. netsnmp_lmsensors_thermal_data_query_template.xml) from the templates folder that is extracted previously
- Devices > [Description]. In Associated Data Queries tab, add ucd/net - lmSensors - Thermal Sensors. You may click Verbose Query to check whether the temperature data can be obtained.
- Click New Graphs in the left menu. You can focus on Data Query [ucd/net - lmSensors - Thermal Sensors] to select the sensors that you want to monitor.
However, I found that different sensors device may use different object identifier (OID) to identify the CPU temperature. So you may need to modify the $oid_array (about line 313) of ss_netsnmp_lmsensors.php. In my f71882fg sensors, the OID is:
"sensorIndex" => ".1.3.6.1.4.1.2021.13.16.5.1.1"
"sensorName" => ".1.3.6.1.4.1.2021.13.16.5.1.2"
"sensorReading" => ".1.3.6.1.4.1.2021.13.16.5.1.3"
Integrated hddtemp to show the graph of Harddisk temperature:
** Please be also reminded that hddtemp must be installed and the hddtemp daemon must be started as well.
In my example, I have two hard disks, and my cacti is installed in /home/admin/cacti. Here is the command to start hddtemp daemon with two hard disks:
/usr/sbin/hddtemp -d /dev/sda /dev/sdb
I recommend to add above line to /etc/rc.local. The daemon will automatically start when the Linux starts.
- Download cacti-linux-hddtemp-1.0.tar.gz and extract it:
tar zxvf cacti-linux-hddtemp-1.0.tar.gz - Copy hddtemp.php to the /home/admin/cacti/scripts/ directory.
- Copy hddtemp.xml to the /home/admin/cacti/resource/script_queries/ directory
- Login to Cacti console and click Import Templates from the left menu
- Upload the basic template XML file (i.e. cacti_template_linux_hddtemp_disk_temperature.xml). If you want grouping graph (e.g. monitoring two hard disks in the same graph), please also upload an related graph template
(e.g. cacti_graph_template_linux_hddtemp_disk_temperature_2x.xml for two hard disks) - Devices > [Description]. In Associated Data Queries tab, add Linux - hddtemp - disk temperature. You may click Verbose Query to check whether the temperature data can be obtained.
- Click New Graphs in the left menu. In the Graph Templates part, Create field, select Linux - hddtemp - disk temperature. In the Data Query [Linux - hddtemp - disk temperature] part, tick the check boxes of /dev/sda and /dev/sdb. Then you can click the Create button. If you don't want to change the title, just can Create button again.
- Click Graph Management in the left menu. Click [Description] - Disks temperature hyperlink which the associated template name is Linux - hddtemp - Disk temperature 2x. Select below matching:
Disk 1: [Description] - Disks temperature /dev/sda
Disk 2: [Description] - Disks temperature /dev/sdb - In Graph Management page, you may delete the single-disk graphs, but you must select Leave the data sources untouched.
- Actually the setup should be done. But my graph only shows the second line. Therefore, I click Graph Templates > Linux - hddtemp - Disk temperature 2x. Click Item # 1 and Item # 5.
For Item # 1:
Data Source: Linux - hddtemp - Disk temperature - (temperature)
Graph Item Type: Area
For Item # 5:
Data Source: Linux - hddtemp - Disk temperature - (temperature)
Graph Item Type: Line1Going back to previous page (Linux - hddtemp - Disk temperature 2x), in Graph Item Inputs part, delete unnecessary items except Disk1 and Disk2, and set it to Disk 1 maps to Item1-4 and Disk 2 maps to Item5-8.
Click Graph Management in the left menu, click [Description] Disks temperature and choose again Disk 1 and Disk 2. That's all!
References:
Linux Pilot 2009年7月號(Vol. 81)
Eric A. Hall - - Software Projects - - Cacti lmSensors/Net-SNMP Sensor Readings
hddtemp template for cacti






