How to Install Cacti Monitoring Server With Nginx

How to Install Cacti Monitoring Server With Nginx

How to Install Cacti Monitoring Server With Nginx

Jul 2, 2015 – 2 min read

Introduction

Cacti is an open-source, web-based network monitoring and graphing tool designed as a front-end application for the open-source, industry-standard data logging tool RRDtool. Cacti allows a user to poll services at predetermined intervals and graph the resulting data. It is generally used to graph time-series data of metrics such as CPU load and network bandwidth utilization.`{`2`}` A common usage is to monitor network traffic by polling a network switch or router interface via Simple Network Management Protocol (SNMP). – Wikipedia

In this tutorial we will:

  • Install Cacti.
  • Configure Cacti to work with Nginx.
  • Configure Cacti.
  • Create devices and graphs.

All commands below are for Debian/Ubuntu Linux distribution.

Install Nginx

To install Nginx execute the command below.


sudo apt-get install nginx

Install SNMPD Service

SNMPD Service is used by Cacti, so it is a required component in order Cacti to work as expected. Let’s install it.


sudo apt-get install snmpd

After the installation we have to do a few configurations.


nano /etc/default/snmpd

Find the row:


export MIBS=

and change it to:


export MIBS=ALL

Save and close the file. Open the configuration file:


nano /etc/snmp/snmpd.conf

For section “AGENT BEHAVIOUR” comment out the line for “connections from the local system only” and uncomment the line “connections on all interfaces”.


#  Listen for connections from the local system only
#agentAddress  udp:127.0.0.1:161
#  Listen for connections on all interfaces (both IPv4 *and* IPv6)
agentAddress udp:161,udp6:[::1]:161

Find the row:


# rocommunity public localhost       #  Full access from localhost

and uncomment it.

Next, search for and find “ACCESS CONTROL” section and add the following record. We will be changing this to reference our specific Cacti server. Use either your cloud server’s domain name or its IP address.


rocommunity secret  CactiServerIpAddress

For example (if the IP address of our server is 1.1.1.1):


rocommunity secret 1.1.1.1

Save and close the file.

The next step is to install MIB files. Here is short information about MIB:

A management information base (MIB) is a database used for managing the entities in a communications network. Most often associated with the Simple Network Management Protocol (SNMP), the term is also used more generically in contexts such as in OSI/ISO Network management model. While intended to refer to the complete collection of management information available on an entity, it is often used to refer to a particular subset, more correctly referred to as MIB-module.

Let’s install it:


sudo apt-get install snmp-mibs-downloader

Usually the installation should go with no issues but if you get this error “E: Package ‘snmp-mibs-downloader’ has no installation candidate”, that means that your are missing a source.list link. Let’s add it.


nano /etc/apt/sources.list

At the end of the file add:


deb http://fr.archive.ubuntu.com/ubuntu precise main multiverse

Save and close the file. Try to install it again. This time it should work! When you are ready with the installation of MIB files, restart SNMPD service.


sudo service snmpd restart

Install Cacti Monitoring Server

Let’s start with:


sudo apt-get install cacti cacti-spine

During the installation of Cacti, you will be asked if you’d like dbconfig-common to setup MySQL for Cacti automatically. This creates a user and database for Cacti, and then imports the necessary data.

cacti installation

You also will be asked to choose Web service. In our case choose “None/Others” because we will configure it to work with Nginx.

cacti installation

Configure Cacti with Nginx

Let’s assume that in our case /var/www is the home directory where are located the websites which are pointing to our server. Let’s also assume that we would like to access Cacti from the domain name example.com. Let’s go to the home directory and create a directory for this domain name.


cd /var/www/
mkdir example

Now we have to create a record in “sites-available” in order Nginx to be able to handle requests sent from outside world to this domain. Let’s go to this directory and create a new file for the domain.


cd /etc/nginx/sites-available/
nano example

Add the following code inside the file.


server {
        listen 80;

        root /var/www/example;
        index index.php index.html index.htm;

        server_name example.com;

         location ~ \.php$ {
                try_files $uri /index.php =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

With the help of this configuration Nginx knows that all requests to the IP address of our server for this domain name and on port 80 must be forwarded to directory /var/www/example. Save and close the file.

Restart Nginx.


service nginx restart

Let’s go to the public directory for this domain.


cd /var/www/example/

Now we have to create a soft link between a sub-directory inside this domain name and the Cacti installation.


ln -s /usr/share/cacti/site cacti

This approach is helpful for those cases when the domain name example.com already has an installed website, for example a blog or another web system, and we would like to access Cacti from example.com/cacti.

But if we want Cacti to be installed on a separate domain then we have to create the soft link between the directory example and the Cacti installation.


cd /var/www/
rm example
ln -s /usr/share/cacti/site example

When you are ready, you have to set up the correct permissions for the directory. In our case let’s assume that we have chosen the first option, to access Cacti from a sub-directory.


chgrp -R www-data example/
chown -R www-data example/
chmod -R 0755 example/

One-Time Setup of Cacti Monitoring Server

Open your web browser and type the domain name in order to access the Cacti Monitoring Server. In our case this is: example.com/cacti. The first time when you open this domain you will see the screen displayed below.

cacti installation

Choose “Next”.

cacti installation

The next page shows the application paths of the “helper” applications that Cacti uses to operate. All of the applications should be green and marked with “[FOUND]”. Click “Finish” to continue.

cacti installation

Next, you’ll be asked to enter the Cacti username and password. These are not the passwords you entered during installation. Instead, enter the following default values.

cacti installation

You are now on your Cacti page.

cacti installation

Configure Cacti

A few options must be changed to ensure that Cacti produces data correctly. On the left-hand navigation panel, click on “Settings” under the Configuration heading.

In the General tab, we want to change some parameters. Change these settings to match what is shown here. Click “Save” when finished.

cacti configuration

Next, click the “Poller” tab on the navigation settings. Change these options and match what is shown here. Click “Save” when finished.

cacti configuration

Whenever the Poller Interval is changed, the cache must be emptied. To do this, click “System Utilities” under the Utilities heading.

Click on “Rebuild Poller Cache” to empty the cache.

Creating Devices and Graphs

To begin graphing, we need to set up device profiles and tell Cacti what to graph. Click “Devices” from the main left menu. In the upper-right corner of the page, click the “Add” button to add a new device. Now we have to fill in the fields displayed below. Click “Create” when you are ready.

cacti configuration

If you see SNMP error in red at the top of the page, restart snmpd service from the Linux console. Click “Save” again when you are ready.

sudo service snmpd restart

Next, scroll down and create some associated graph templates and associated data queries.

cacti configuration

Click “Create” at the bottom of the page when you are ready.

If you want like to change the graphs and the data collectors, click “Devices” from the left main menu and choose the device which you want to change. At the top of the page you will see three buttons: “Create Graphs for this Host”, “Data Source List” and “Graph List”. Choose “Data Source List” or “Graph List” in order to change the data sources or the graphs.

In order to see the data collected by Cacti, click “Graphs” tab at the top of the page. The collection of data might take a while (5 to 10 minutes) so if you come back in few hours you will see colorful graphs displaying the collected data.

Cacti graphs

All ready! We have Cacti Monitoring Server up and running. Click on each graph to show daily, weekly, monthly, and yearly graphs for that same resource.

If you need assistance with Cacti, contact me.

(The header image is taken from DigitalOcean website.)

Tags:
,
No Comments

Post A Comment