Cacti- The Complete RRDTool-based Graphical Solution

Cacti- The Complete RRDTool-based Graphical Solution

by -
0 2031

Introduction

Cacti tool is an open source web based network monitoring and system monitoring graphing solution for IT business. Cacti enables a user to poll services at regular intervals to create graphs on resulting data using RRDtool. Generally, it is used to graph time-series data of metrics such as network bandwidth utilization, CPU load, running processes, disk space etc.

 

ct2

 

In this how-to we are going to show you how to install and setup complete network monitoring application called Cacti using Net-SNMP tool on RHEL 6.x/5.x, CentOS 6.x/5.x and Fedora  systems using YUM package manager tool.

Cacti:

About Cacti:

Cacti is a complete network graphing solution designed to harness the power of RRDTool’s data storage and graphing functionality. Cacti provides a fast poller, advanced graph templating, multiple data acquisition methods, and user management features out of the box. All of this is wrapped in an intuitive, easy to use interface that makes sense for LAN-sized installations up to complex networks with hundreds of devices.

Cacti tool is an open source web based network monitoring and system monitoring graphing solution for IT business. Cacti enables a user to poll services at regular intervals to create graphs on resulting data using RRDtool. Generally, it is used to graph time-series data of metrics such as network bandwidth utilization, CPU load, running processes, disk space etc.

Data Sources:

To handle data gathering, you can feed cacti the paths to any external script/command along with any data that the user will need to “fill in”, cacti will then gather this data in a cron-job and populate a MySQL database/the round robin archives.

Data Sources can also be created, which correspond to actual data on the graph. For instance, if a user would want to graph the ping times to a host, you could create a data source utilizing a script that pings a host and returns it’s value in milliseconds. After defining options for RRDTool such as how to store the data you will be able to define any additional information that the data input source requires, such as a host to ping in this case. Once a data source is created, it is automatically maintained at 5 minute intervals.

Graphs:

Once one or more data sources are defined, an RRDTool graph can be created using the data. Cacti allows you to create almost any imaginable RRDTool graph using all of the standard RRDTool graph types and consolidation functions. A color selection area and automatic text padding function also aid in the creation of graphs to make the process easier.

Not only can you create RRDTool based graphs in cacti, but there are many ways to display them. Along with a standard “list view” and a “preview mode”, which resembles the RRDTool frontend 14all, there is a “tree view”, which allows you to put graphs onto a hierarchical tree for organizational purposes.

User Management

Due to the many functions of cacti, a user based management tool is built in so you can add users and give them rights to certain areas of cacti. This would allow someone to create some users that can change graph parameters, while others can only view graphs. Each user also maintains their own settings when it comes to viewing graphs.

Templating

Lastly, cacti is able to scale to a large number of data sources and graphs through the use of templates. This allows the creation of a single graph or data source template which defines any graph or data source associated with it. Host templates enable you to define the capabilities of a host so cacti can poll it for information upon the addition of a new host.

I m providing you a snapshot , so that you can some view of cacti graphs before starting this lab and practical.

Have a look at the snapshot.

ct1

Yes, it will show you the graphs, which you want , either it is of memory, interface, processes etc.

Cacti Required Packages

The Cacti required following packages to be installed on your Linux operating systems like RHEL / CentOS / Fedora.

  1. Apache : A Web server to display network graphs created by PHP and RRDTool.
  2. MySQL : A Database server to store cacti information.
  3. PHP : A script module to create graphs using RRDTool.
  4. PHP-SNMP : A PHP extension for SNMP to access data.
  5. NET-SNMP : A SNMP (Simple Network Management Protocol) is used to manage network.
  6. RRDTool : A database tool to manage and retrieve time series data like CPU load, Network Bandwidth etc.

Installing Cacti Required Packages on RHEL / CentOS / Fedora

First, we need to install following dependency packages one-by-one using YUM package manager tool.

Set the hostname.

# vi /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=cactiserver.com

GATEWAY=192.168.0.254

# vi /etc/hosts

192.168.0.155 cactiserver.com

# service network restart

# init 6

Now to check hostname,put command hostname.

[root@cactiserver ~]# hostname

cactiserver.com

Step 1: Install Apache

# yum install httpd httpd-devel -y

ct3

Steps Ahead

Step 2:# yum install mysql mysql-server -y

Step 3:Install PHP
# yum install php-mysql php-pear php-common php-gd php-devel php php-mbstring php-cli
Step 4:Install PHP-SNMP
# yum install php-snmp -y

Step 5:Install NET-SNMP
# yum install net-snmp-utils net-snmp-libs -y
Step 6:Install Rrdtool
# yum install rrdtool -y

Step 7:Staring Apache, MySQL and SNMP Services

Once you’ve installed all the required software’s for Cacti installation, lets start them one-by-one using following commands.

On RHEL/CentOS 6.x/5.x and Fedora 18-12
# service httpd start
# service mysqld start
# service snmpd start

ct4
Configure Start-up Links

Step 8:Configuring Apache, MySQL and SNMP Services to start on boot.

On RHEL/CentOS 6.x/5.x and Fedora 18-12
# /sbin/chkconfig --levels 345 httpd on
# /sbin/chkconfig --levels 345 mysqld on
# /sbin/chkconfig --levels 345 snmpd on
 

Install Cacti on RHEL / CentOS / Fedora

Here, you need to install and enable EPEL Repository. Once you’ve enabled repository, type the following command to install Cacti application.

Step 9:Install cacti package.
# yum install cacti -y

Before installing cacti package, we need to install epel repository.

What is EPEL

EPEL (Extra Packages for Enterprise Linux) is open source and free community based repository project from Fedora team which provides 100% high quality add-on software packages for Linux distribution including RHEL (Red Hat Enterprise Linux), CentOS, and Scientific Linux. Epel project is not a part of RHEL/Cent OS but it is designed for major Linux distributions by providing lots of open source packages like networking, sys admin, programming, monitoring and so on. Most of the epel packages are maintained by Fedora repo.

Why we use EPEL repository?

  1. Provides lots of open source packages to install via Yum.
  2. Epel repo is 100% open source and free to use.
  3. It does not provide any core duplicate packages and no compatibility issues.
  4. All epel packages are maintained by Fedora repo.

How To Enable EPEL Repository in RHEL/CentOS 7/6/5?

First, you need to download the file using Wget and then install it using RPM on your system to enable the EPEL repository. Use below links based on your Linux OS versions. (Make sure you must be root user.

RHEL/CentOS 6 32-64 Bit

## RHEL/CentOS 6 32-Bit ##
# wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
## RHEL/CentOS 6 64-Bit ##
# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm

RHEL/CentOS 5 32-64 Bit

## RHEL/CentOS 5 32-Bit ##
# wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
# rpm -ivh epel-release-5-4.noarch.rpm
## RHEL/CentOS 5 64-Bit ##
# wget http://download.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
# rpm -ivh epel-release-5-4.noarch.rpm

ct5

# yum install cacti -y

Step 10: Set up mysql pasword for root.

[root@cactiserver ~]# /usr/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we’ll need the current

password for the root user. If you’ve just installed MySQL, and

you haven’t set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none):

Enter current password for root (enter for none):

OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

Set root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

… Success!

Step 11:Now test the mysql root password by below command.

[root@cactiserver ~]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 12

Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> create database cacti; (create cacti database)

Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY ‘redhat’;

Now grant access to cacti user of cacti database, whose password we have put in here.

With this single command, we have create user ,given its password and given this user a gant access to database cacti.

mysql> FLUSH privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> quit;

Bye

ct6

Install Cacti Tables to MySQL

Find out the database file path using RPM command, to install cacti tables into newly created Cacti database, use the following command.

# rpm -ql cacti | grep cacti.sql
Sample Output:
/usr/share/doc/cacti-0.8.8b/cacti.sql

Step 12: Now we’ve of the location of Cacti.sql file, type the following command to install tables, here you need to type the Cacti user password.

# mysql -u cacti -p cacti < /usr/share/doc/cacti-.8.8b/cacti.sql
Enter password:

ct7
Step 13: Configure MySQL settings for Cacti

Open the file called /etc/cacti/db.php with any editor.

# vi /etc/cacti/db.php

Make the following changes and save the file. Make sure you set password correctly.

/* make sure these values reflect your actual
database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "redhat";
$database_port = "3306";
$database_ssl = false;

ct8

Step 14: Configuring Firewall for Cacti.

If you are using firewall , you have allow 80 port.you can use below commands to allow port 80 from your machine.

On RHEL/CentOS 6.x/5.x :
[root@cactiserver ~]# iptables -A INPUT -p udp --dport 80 -j ACCEPT
[root@cactiserver ~]# iptables -A INPUT -p tcp --dport 80 -j ACCEPT
[root@cactiserver~]#  service iptables save

 


Configuring Apache Server for Cacti Installation

Open file called /etc/httpd/conf.d/cacti.conf with your choice of editor.

# vi /etc/httpd/conf.d/cacti.conf

You need to enabled access to Cacti application for your local network or per IP level. For example we’ve enabled access to our local LAN network 192.168.0.0/24 In your case, it would be different.

Alias /cacti    /usr/share/cacti

 

<Directory /usr/share/cacti/>
        Order Deny,Allow
        Deny from all
        Allow from 192.168.0.0/24
</Directory>

In latest version of Apache (ex: Apache 2.4), you may need to change according to the following settings.

Alias /cacti    /usr/share/cacti
<Directory /usr/share/cacti/>
        <IfModule mod_authz_core.c>
                # httpd 2.4
                Require all granted
        </IfModule>
        <IfModule !mod_authz_core.c>
                # httpd 2.2
                Order deny,allow
                Deny from all
                Allow from all
        </IfModule>
</Directory>

Here we are using apache 2.4, so use the below one.
[root@cactiserver~]# vi /etc/httpd/conf.d/cacti.conf 

ct9
ct10

Setting Cron for Cacti

Open file /etc/cron.d/cacti.

# vi /etc/cron.d/cacti

Uncomment the following line. The poller.php script runs every 5mins and collects data of known host which is used by Cacti application to display graphs.

#*/5 * * * *   cacti   /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1
 

Running Cacti Installer Setup:

Finally, Cacti is ready, just go to http://192.168.0.155/cacti/ & follow the installer instruction through the following screens. Click Next button.

ct11

Please choose installation Type as “New Install“.

ct12

Make sure all the following values are correct before continuing. Click Finish button.

ct13

 

Put the username and password as admin to login.

ct14

Now , it will ask for a password, if you want to reset.

ct15

Finally the cacti that will open on a web panel, will look like this.

ct16

How to Create New Graphs for Server (Linux Server as a client for cacti)

To create graphs, Click on New Graphs –> Select Host –> Select SNMPInterface Statistics and Select a graph type In/Out Bits. Click on Create button. Please refer screen below.

ct17

Graph of /dev/sda1 and /dev/sda3 will be created by selecting them.

Click on create and then click oin graphs to check the created grpahs for local host.

ct18

You can cross check, please look at below snapshot.

ct19

 

ct20

 

ct21

 

ct22

These are above some snapshots of cacti graphs of localhost machine of server.And i m sure that it will give some deep details about graph of cacti .

Manage cacti server to view graphs of linux client machine

Now we are going towards , how to add linux client machine to cacti server and how we will manage cacti server to view graphs of linux client machine.

Here are below steps you have to follow.

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

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

[root@localhost ~]# yum install net-snmp-utils php-snmp net-snmp-libs -y

Then edit its configuration like the following.

root@server:~# vim /etc/snmp/snmpd.conf

Append / modify it as follows (see snmpd.conf man page for details):

# First, map the community name “public” into a “security name”

# sec.name source community

com2sec ConfigUser default public

com2sec Alluser default kvit

####

# Second, map the security name into a group name:

# groupName securityModel securityName

#group ConfigGroup v1 notConfigUser

group ConfigGroup v2c notConfigUser

group AllGroup v2c Alluser

####

# Third, create a view for us to let the group have rights to:

# Make at least snmpwalk -v 1 localhost -c public system fast again.

# name incl/excl subtree mask(optional)

view systemview included .1.3.6.1.2.1.1

view systemview included .1.3.6.1.2.1.25.1.1

view Allview included .1

####

# Finally, grant the group read-only access to the systemview view.

# group context sec.model sec.level prefix read write notif

access ConfigGroup “” any noauth exact systemview none none

access AllGroup “” any noauth exact Allview none none

ct23

You have to add these lines in config file.

===============================================================

com2sec Alluser default kvit

group AllGroup v2c Alluser

view Allview included .1

access AllGroup “” any noauth exact Allview none none

===============================================================

The above text is noted with basic information on the function of each configuration line. In short, we’re creating this scenarios for the polling.

AllUser is assigned to AllGroup and may only use SNMP security model 2c , AllGroup can use the AllView .

AllView is assigned to the entire OID tree, and all of this is referenced in an SNMP poll by the secret, and unique community string kvit.

ct24

To check and testing of snmp service of localhost , machine itself.

Snmpwalk is testing command for snmp.I will also put one intresting article regarding snmp.

[root@localhost ~]# snmpwalk -v 2c -c kvit -O e 127.0.0.1

You will many lines.

ct25

You can also test the snmp service connectivity on server machine or cacti server by putting below command.

[root@cactiserver tmp]# snmpwalk -v 2c -c kvit -0 e 192.168.0.195

ct26

 

You will get output like above lines on cacti server.

Here above you will have a look at word MIB , which is very important while learning snmp.

Here are some brief information on these,please read these while going through this practical.

MIB stands for Management Information Base and is a collection of information which is organized hierarchically. The various pieces of information are accessed by a protocol such as SNMP. There are two types of MIBs: scalar ones and tabular ones. Scalar objects define a single object instance whereas tabular objects define multiple related object instances grouped in MIB tables.

OIDs or Object Identifiers uniquely identify manged objects in an MIB hierarchy. It can be depicted as a tree whose nodes are assigned by different organizations. Generally, an OID is a long sequence of numbers, coding the nodes, separated by dots. Top level MIB object IDs (OIDs) belong to different standard organizations. Vendors define private branches including managed objects for their own products

Configuring Cacti to Monitor Linux Servers

Once that is done you will need to add the new box as a device on your Cacti web interface. I wont go into much detail with that in this post, but here’s a quick walk-through.

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

Step 1: Go to console and devices option.

ct27

Step 2:Go to add option the right-top corner.

ct28

Step 3: Please acknowledge some changes.

ct29

Description
Give this host a meaningful description.
19
Hostname
Fully qualified hostname or IP address for this device.

SNMP Version
Choose the SNMP version for this device.
Not In Use Version 1 Version 2 Version 3 
SNMP Community
SNMP read community for this device.

Above are the following options to be changed.

Then click on create option at bottom-right. Now, when your machine will be added, you will get this type ,please look at below snapshot.

ct30

Now at the bottom, you can add some options of which you want to show or view some graphs.

Here i have added some options here, have a look below options.

ct31

 

And after adding ,please save all this.

And then we proceed to creating the graphs.Now , click on right side “click on create graphs for this host.

ct32

Then you will get this type ,look at below snapshot.

ct33

ct34

Select options as per your requirement, and also select option , 64-bit Counters.

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.

ct35

 

Finally ,click on create.

ct36

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

Again ,click on create option.

Creating Graph Trees

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

Click on Console and then graph trees and then default tree.

ct37

ct38

Click on add option.

Select graph, where there is header option.

ct39

And then select the graph option of which you want to show or view graphs.

ct40

Then finally save.

Then finally click on graphs to view the graphs.Here below is final snapshot of linux client machine graphs ( 192.168.0.195- which is linux clinet mahcine.)

In next topic, we will see how to add windows clinet machine to linux cacti server.

ct41

I think above snapshot will better clear the whole picture.You can compare with the cli mode and graphs.

In case any query, you can mail us at lalitvohra04@gmail.com or linux@kvit.in. We will be always there to help you.If anything new, you will be welcome to share your thoughts.

Download PDF

NO COMMENTS

Leave a Reply

Required Captcha *