Monday 19 December 2016

How to install & configure MRTG with RRDTools and Router2 on Ubuntu 14.04


Install & configure MRTG with RRDTools and Router2 on Ubuntu 14.04



What is MRTG?
The Multi Router Traffic Grapher (MRTG) is a tool to monitor the traffic load on network links. MRTG generates HTML pages containing PNG images which provide a LIVE visual representation of this traffic.

What is RRDTool?
RRDtool is the OpenSource industry standard, high performance data logging and graphing system for time series data. RRDtool can be easily integrated in shell scripts, perl, python, ruby, lua or tcl applications.

What is Router2?
routers2.cgi is a frontend to data stored in rrdtool databases. This is written in Perl, and requires the MRTG system to collect the data. Although the name would indicate otherwise, this frontend will work in the same way as 14all.cgi, and can provide a generic frontend for ALL MRTG collected data.

Step 1: Update & Upgrade the Ubuntu Server:

# apt-get -y update
# apt-get -y upgrade

Step 2: Preparation for Installing MRTG With RRDTools and Router2:

# apt-get -y install mrtg mrtg-ping-probe rrdtool librrds-perl snmp snmpd snmp-mibs-downloader libapache2-mod-perl2 libnet-snmp-perl libgd-gd2-perl

*Note: The installation requires round about 60 packages. Attention: The installation process from MRTG asks a single question, whether or not the root user should be the only one who can read the default configuration file from MRTG (/etc/mrtg.cfg). In our scenario, this can be answered with “Yes”, which is also the default option in this question.

Step 3: Install WebServer (Apache2) & Php-fpm and Preconfigured it according to the MRTG and Router2:

# apt-get -y install apache2
# vi /etc/apache2/sites-available/000-default.conf

#### Comment out/Delete all the lines and add the following lines;

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
         <Directory "/usr/lib/cgi-bin/">
                 AllowOverride None
                 Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                 Require all granted
         </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

--- Save & Quit (:wq) ---

# apt-get -y install php5-fpm php5
# service apache2 restart
# service php5-fpm restart

# vi /var/www/index.html

### Add these lines

<head>
<meta http-equiv="refresh" content="0; URL=http://<IP-Address-Of-Server>/cgi-bin/routers2.cgi">
</head>

--- Save & Quit (:wq) ---

Step 4: Configure the Environment for the MRTG with RRDTool:

*Note: We must create some folders in order to store our configuration and rrd files. I decided to store the configs under the /etc folder while the rrd files under the /var folder.

# mkdir /var/mrtg #for rrd directory
# mkdir /etc/mrtg #for config files

*Note: Note that RRDtool itself needs no further configuration since it is always used from Routers2 directly and thus needs no specific configuration.

# cd /tmp
# wget http://www.steveshipway.org/software/rrd/routers2-v2.23.tar.gz
# tar xfv routers2-v2.23.tar.gz
# cd routers2-v2.23/
# perl install.pl

Continue [yes]? yes
Document root? /var/www
CGI directory? /usr/lib/cgi-bin
MRTG config directory? /etc/mrtg
MRTG files [*.cfg]? Enter
RRD directory [/tmp]? /var/mrtg
Perl executable [/usr/bin/perl]? Enter
Configuration file [/var/mrtg/routers2.conf]? Enter
Activate routingtable extensions [no]? Enter
'usebigk' option [mixed]? no
auth option [none]? Enter
Caching option [no]? Enter
Can I mail [no]? Enter

INSTALLING SOFTWARE

Perl is     : /usr/bin/perl
MRTG files  : /etc/mrtg/*.cfg
RRD files   : /var/mrtg
Doc root    : /var/www
CGI bin     : /usr/lib/cgi-bin
Config file : /var/mrtg/routers2.conf
Routingtable: INACTIVE
Compact page: ENABLED
Caching     : DISABLED
'usebigk'   : no
Auth option : NONE
Mail Steve  : no
Other options can be set later by modifying the Config file
Continue to install [no]? yes

# vi /var/mrtg/routers2.conf

### Add these lines at the end of the file,

charset = utf-8         #Since otherwise the degree symbol ° isn't displayed correctly
actuals = yes           #Show actual values in a popup
defaulttarget = summary #Show the summary page first
graphstyle = x3         #Show the biggest image by default
graphtype = w           #Show the weekly graph by default
percentile = yes        #Percentile calculation
sorder = l2 l2D x3 x3D  #Offer only the huge images
showtotal = yes         #A total line on the incoming and outgoing graphs
compact = no            #I am not using the compact graphs. Maybe you want to...
daystart = 8            #For displaying a highlighted area for the working day
dayend   = 18           #Ditto
windowtitle = Title     #Here you can customize the title of the webpage
bgcolour = #fffffff     #Otherwise some targets have a purple background
twinmenu = yes          #Since we all have widescreen displays nowadays
showfindbox = no        #I am not monitoring that many devices

--- Save & Quit (:wq) ---

# vi /etc/mrtg.cfg

## Comment out/Delete all the Lines and add the following lines at the end

#Directory in which the RRD files will be stored
WorkDir: /var/mrtg
#Tells MRTG to use RRD instead of its own log format
LogFormat: rrdtool
#To have multiple instances of MRTG running to immediately pass through all targets
Forks: 4
#Use the configs in the mrtg subfolder (/etc/mrtg)
Include: mrtg/*.cfg

--- Save & Quit (:wq) ---

# a2enmod cgi
# service apache2 restart

Step 5: Test the Setup on Browser:

http://<ip-address>/cgi-bin/routers2.cgi or http://<ip-address>

Thanks For Visiting on My Blog, For More Tutorials Keep Visiting My Blog.