How to Install MRTG in Ubuntu

To Install MRTG in Ubuntu

MRTG is a tool that used to monitor the traffic load on network links. MRTG stands for Multi Router Traffic Grapher, which generates the HTML pages to provide a live visual representation. The external SNMP package is not required for the installation process. This article explains the installation of MRTG in Ubuntu.

Installation of MRTG

For installing MRTG, you need to install Apache and SNMP packages.

To install Apache and SNMP

Utilize the following command to install the Apache and SNMP packages.

root@linuxhelp:~#  apt-get install apache2 snmpd snmp
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1
  libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0
.
.
.
Processing triggers for libc-bin (2.21-0ubuntu4) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (225-1ubuntu9) ...
Processing triggers for ufw (0.34-2) ...


Open the configuration file of SNMP and uncomment the following lines as shown below,

root@linuxhelp:~#  vi /etc/snmp/snmpd.conf
rocommunity public localhost


Restart the SNMP service to take effect.

root@linuxhelp:~# systemctl restart snmpd


Now its time to install the MRTG package.

root@linuxhelp:~# apt-get install mrtg
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libsnmp-session-perl
.
.
.
Processing 2 added doc-base files...
Processing triggers for man-db (2.7.4-1) ...
Setting up libsnmp-session-perl (1.13-1.1) ...
Setting up mrtg (2.17.4-2ubuntu2) ...


Then create a directory on the Document root location.

root@linuxhelp:~# mkdir /var/www/html/mrtg


Take backup of MRTG configuration file with the following command.

root@linuxhelp:~# cp /etc/mrtg.cfg /etc/mrtg.cfg.real


Now change the MRTG workdir location.

root@linuxhelp:~# vim /etc/mrtg.cfg
WorkDir: /var/www/html/mrtg


Here you need to create a configuration file for MRTG.

root@linuxhelp:~# cfgmaker public@localhost >  /etc/mrtg.cfg
--base: Get Device Info on public@localhost:
--base: Vendor Id: Unknown Vendor - 1.3.6.1.4.1.8072.3.2.10
--base: Populating confcache
--base: Get Interface Info
.
.
.
--base: Walking ifSpeed
--snpd:   public@localhost: ->  1 ->  ifSpeed = 10000000
--snpd:   public@localhost: ->  2 ->  ifSpeed = 1000000000


Once the config file is created then create an index file for the webserver.

root@linuxhelp:# indexmaker /etc/mrtg.cfg >  /var/www/html/mrtg/index.html


Open the web browser and enter your /server IP/mrtg/ to view the presentation of MRTG graph.

MRTG Description

You can monitor Daily Graph.

Weekly graph

Monthly graph

Yearly Graph

Tag : Traffic
Comment
banjarabikash
Jul 20 2019
at last step after indexmaker /etc/mrtg.cfg > /var/www/html/mrtg/index.html this step it generate error by saying did not find any matching data in cfg file. how can i solve ?
Add a comment
FAQ
Q
What is MRTG Tool?
A
MRTG is a tool that used to monitor the traffic load on network links. MRTG stands for Multi Router Traffic Grapher, which generates the HTML pages to provide a live visual representation.
Q
What protocol does this MRTG rely on?
A
MRTG relies on SNMP Protocol.

Sample Output:

*/5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
Q
How Do I Create MRTG For My Router at 192.X.X.X?
A
To craete MRTG monitoring for your router,
# cfgmaker --global 'WorkDir: /var/www/mrtg' --output /etc/mrtg/mrtg.cfg public@192.X.X.X.
Q
How Do I Password Protect My Graphs on MRTG?
A
Set Apache Password Protected Directories With .htaccess File on MRTG.
Q
I have followed all the steps above, do the checks along the way and when I got to the webpage I get Forbidden
You don’t have permission to access /mrtg on this server.
A
You need to set correct permission on the mrtg folder so that web server user can read the files:
Assign permission as follows,
chmod 0775 /path/to/your/mrtg/directory