This article is focusing installing and configure MRTG with CPU,Memory and Disk Usage Graphs examples for Debian Ubuntu and Kubuntu Users and may be work for some debian based distributions.
MRTG is 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.
MRTG Requirements
Apache webserver with perl support
NET-SNMP
GD
Libpng
zlib
If you want to download MRTG you can download from here
Preparing you System for MRTG Instalaltion
First you need to install the required compilers
#apt-get install gcc make g++
Apache 2 Installation with perl support
Follow these instructions to install apache2 with perl support
MRTG Installation
Now we need to install mrtg and snmp
Installing MRTG in Debian, Ubuntu and Kubuntu
#apt-get install mrtg snmpd
The installation will create an mrtg subdirectory where the Apache Web pages reside. On your Debian,ubnutu,kubuntu systems the path of this subdirectory is:
/var/www/mrtg
Now you need to edit the mrtg configuration file to edit the some of the settings
File is located at /etc/mrtg.cfg you need to change the global settings as follows
# Global Settings
RunAsDaemon: yes
EnableIPv6: no
WorkDir: /var/www/mrtg
Options[_]: bits,growright
WriteExpires: Yes
Title[^]: Traffic Analysis for
You will find a crontab running every 5 minutes as user root
# cat /etc/cron.d/mrtg
0-55/5 * * * * root if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ]; then env LANG=C /usr/bin/mrtg /etc/mrtg.cfg >> /var/log/mrtg/mrtg.log 2>&1; fi
Now we need to assign the snmp community name in snmp configration file /etc/snmp/snmpd.conf
# sec.name source community
# com2sec paranoid default public
com2sec readonly default public
#com2sec readwrite default private
Now you need to restart the snmp service
#/etc/init.d/snmpd restart
The configuration file creating using
#cfgmaker public@localhost > /etc/mrtg.cfg
Creating a configuration file for a device using cfgmaker
#cfgmaker [email protected] >> /etc/mrtg.cfg
With the configuration file created correctly there’s only one other thing you have to do and that’s to use the indexmaker utility to create the summary home page. Since you have to re-run this command every time you make certain changes to the /etc/mrtg.cfg configuration file.
Creating index file for the webserver using indexmaker
#indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html
Now you need to reboot your system wait for five minutes or so and then take a look at your summary home page. If your Debian,ubuntu,kubuntu system’s IP address is 192.168.0.1 then you’d type in the following in the address bar of a browser running on a system on the same network:
http://192.168.0.1/mrtg/
Your summary home page should come up with a graph for each target entry in the configuration file. If a graph looks like there’s no data on it, click on it and check the statistics to see if any traffic is being seen. Small amounts of traffic won’t show up on the graphs because we used the Unscaled statement
Some of examples how to monitor cpu , memory , Disk usage
CPU Usage
/etc/mrtg/cpu.cfg
WorkDir: /var/www/mrtg
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:[email protected]+ ssCpuRawSystem.0&ssCpuRawSystem.0:[email protected]+
ssCpuRawNice.0&ssCpuRawNice.0:[email protected]
RouterUptime[localhost.cpu]: [email protected]
MaxBytes[localhost.cpu]: 100
Title[localhost.cpu]: CPU Load
PageTop[localhost.cpu]: Active CPU Load %
Unscaled[localhost.cpu]: ymwd
ShortLegend[localhost.cpu]: %
YLegend[localhost.cpu]: CPU Utilization
Legend1[localhost.cpu]: Active CPU in % (Load)
Legend2[localhost.cpu]:
Legend3[localhost.cpu]:
Legend4[localhost.cpu]:
LegendI[localhost.cpu]: Active
LegendO[localhost.cpu]:
Options[localhost.cpu]: growright,nopercent
Memory Usage
/etc/mrtg/mem.cfg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[localhost.mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.6.0:public@localhost
PageTop[localhost.mem]:Free Memory
WorkDir: /var/www/mrtg
Options[localhost.mem]: nopercent,growright,gauge,noinfo
Title[localhost.mem]: Free Memory
MaxBytes[localhost.mem]: 1000000
kMG[localhost.mem]: k,M,G,T,P,X
YLegend[localhost.mem]: bytes
ShortLegend[localhost.mem]: bytes
LegendI[localhost.mem]: Free Memory:
LegendO[localhost.mem]:
Legend1[localhost.mem]: Free memory, not including swap, in bytes
Memory Monitoring (Total Versus Available Memory)
/etc/mrtg/memfree.cfg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[server.memory]: memAvailReal.0&memTotalReal.0:public@localhost
Title[server.memory]: Free Memory
PageTop[server.memory]: < H1 >Free Memory< /H1 >
MaxBytes[server.memory]: 100000000000
ShortLegend[server.memory]: B
YLegend[server.memory]: Bytes
LegendI[server.memory]: Free
LegendO[server.memory]: Total
Legend1[server.memory]: Free memory, not including swap, in bytes
Legend2[server.memory]: Total memory
Options[server.memory]: gauge,growright,nopercent
kMG[server.memory]: k,M,G,T,P,X
Memory Monitoring (Percentage usage)
/etc/mrtg/mempercent.cfg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Title[server.mempercent]: Percentage Free Memory
PageTop[server.mempercent]: < H1 >Percentage Free Memory< /H1 >
Target[server.mempercent]: ( memAvailReal.0&memAvailReal.0:publicy@localhost ) * 100 / ( memTotalReal.0&memTotalReal.0:public@localhost )
options[server.mempercent]: growright,gauge,transparent,nopercent
Unscaled[server.mempercent]: ymwd
MaxBytes[server.mempercent]: 100
YLegend[server.mempercent]: Memory %
ShortLegend[server.mempercent]: Percent
LegendI[server.mempercent]: Free
LegendO[server.mempercent]: Free
Legend1[server.mempercent]: Percentage Free Memory
Legend2[server.mempercent]: Percentage Free Memory
Disk Usage
/etc/mrtg/disk.cfg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[server.disk]: dskPercent.1&dskPercent.2:public@localhost
Title[server.disk]: Disk Partition Usage
PageTop[server.disk]: < H1 >Disk Partition Usage /home and /var< /H1 >
MaxBytes[server.disk]: 100
ShortLegend[server.disk]: %
YLegend[server.disk]: Utilization
LegendI[server.disk]: /home
LegendO[server.disk]: /var
Options[server.disk]: gauge,growright,nopercent
Unscaled[server.disk]: ymwd
Creating jobs for CPU , Memory and Disk Usage
CPU
/etc/cron.mrtg/cpu
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/cpu.cfg
Memory
/etc/cron.mrtg/mem
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/mem.cfg
Memory Free
/etc/cron.mrtg/memfree
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/memfree.cfg
Memory Percentage
/etc/cron.mrtg/mempercent
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/mempercent.cfg
Disk
/etc/cron.mrtg/disk
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/disk.cfg
Run each script 3 times (disregard the warnings)
/etc/cron.mrtg/cpu
/etc/cron.mrtg/mem
/etc/cron.mrtg/memfree
/etc/cron.mrtg/mempercent
/etc/cron.mrtg/disk
Make the Index Files
#/usr/bin/indexmaker –output=/var/www/mrtg/index.html \
–title=”Memory and CPU Usage ” \
–sort=name \
–enumerate \
/etc/mrtg/cpu.cfg \
/etc/mrtg/mem.cfg \
/etc/cron.mrtg/memfree \
/etc/cron.mrtg/mempercent \
/etc/cron.mrtg/disk
Make the mrtg.cfg file
#cfgmaker –global “WorkDir: /var/www/mrtg/” \
–global “Options[_]: growright,bits” \
–ifref=ip \
public@localhost > /etc/mrtg/mrtg.conf
Cronjob setup
/bin/cat >> /var/spool/cron/crontabs/root
*/5 * * * * /bin/run-parts /etc/cron.mrtg 1> /dev/null
Now you logon to your web browser http://192.168.0.1/mrtg/ and Now you should see CPU,Memory and Disk Usage graphs.
If you want more documentation about MRTG check here
Ok, I followed your howto, got it to work but your examples for cpu, mem, etc, really miss some PATHS and proper tags, I recommended you try to follow it š
Just some hints on thins that hit me:
– Ubuntu (at least) adds the mrtg cron job by default, no need to add one (except the “run-parts /etc/cron.mrtg”, that is needed)
– Missing or wrong WorkDir in all examples (the /var/www/htdocs/mrtg one)
– Indexmaker step, I added the previous mrtg.cfg in the list so that it prints the traffic graph
– tags, mrtg does not take them when the are formatted like this , you have to squeeze it like this:
– lots of warning/error messages when launching the cpu, mem, memfree, etc configs, anyways… seems to work
Thanks for this article, with just minor fuss I am up and running. alt
thanks for your nice point and i have corrected some it helps more people.
I got this error:
root@host:/home/beko# cfgmaker public@localhost > /etc/mrtg.cfg
SNMP Error:
no response received
SNMPv1_Session (remote host: “localhost” [127.0.0.1].161)
community: “public”
request ID: 2006478049
PDU bufsize: 8000 bytes
timeout: 2s
retries: 5
backoff: 1)
at /usr/share/perl5/SNMP_util.pm line 627
SNMPWALK Problem for 1.3.6.1.2.1.1 on public@localhost::::::v4only
at /usr/bin/cfgmaker line 919
WARNING: Skipping public@localhost: as no info could be retrieved
any idea?
this error related to SNMP response from your client check snmp is configured properly or not
I’m not understand this line
Creating jobs for CPU , Memory and Disk Usage
you need to create each one of the files menctioned with the details provided
Yes , sure but how can I do :
CPU
/etc/cron.mrtg/cpu
vi /etc/cron.mrtg/cpu right???
Some notes:
The snmpd restart command has a typo.
You should warn people about wrapping for the cpu.cfg file. This got me as I copy/pasted (copy/pasting from the website is very strange, it also nukes dashes and quotes).
The memfree.cfg, mempercent.cfg and disk.cfg sample files are missing the WorkDir directive so that they don’t work.
Also cpu.cfg and mem.cfg don’t have any tag in the PageTop property so that indexmaker choked on them. indexmaker also choked on every single other .cfg file because it does not like ” and wants ” instead (no space). Same for the closing tags.
The last indexmaker command looks wrong as it mixed .cfg files and cron scripts:
> /usr/bin/indexmaker \u2013output=/var/www/mrtg/index.html \
[…]
> /etc/mrtg/cpu.cfg \
> /etc/mrtg/mem.cfg \
> /etc/cron.mrtg/memfree \
Also, why not start with /etc/mrtg.cfg which we created in one of the first steps and now contains all the network interfaces?
Finally, why does the last cfgmaker command write to /etc/mrtg/mrtg.conf rather than /etc/mrtg.cfg? This mrtg.conf is not referenced anywhere else so I don’t see what’s the point. And if it should have been /etc/mrtg.cfg, then why have us run another cfgmaker command before?
Also, why run this cfgmaker command after indexmaker? Shouldn’t it be the other way around?
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
all on one line.
I don’t get it.
[ Error writing /etc/cron.mrtg/cpu: No such file or directory ]
hi Thanks for the tutorial.
Am experiencing a problem when I run:
/usr/bin/indexmaker -output=/var/www/mrtg/index.html -title=”Memory and CPU Usage” /etc/mrtg/cpu.cfg
I get the following error:
ERROR: CFG Error Unknown Option “sscpurawnice.0&sscpurawnice.0” on line 5 or above.
Check doc/reference.txt for Help
Any ideas?
In response to jamie:
Make sure that you don’t have an extra line break. That should all be on one line in the cfg file.
I was good up until the, “examples how to monitor cpu, memory, disk usuage”.
These examples, should I create the /etc/mrtg/cpu.cfg /mem.cfg /memfree.cfg /mempercent.cfg
/disk.cfg files? Or are these already created? Should I just copy and past what is listed
above for these .cfg files? Is there anything I need to change to be specific for my devices?
Also the “Creating Jobs for CPU, Memory and disk usuage”, do I create these files , the one for
cron.mrtg/cpu /mem /memfree /mempercent /disk. I am using Ubuntu, which is very similar
to Debian. I can not seem to locate any of these files in the locations were you said they were
located. Not to mention when I did try creating them, it said permission denied.
Please help. I have MRTG up and working, and would like to tie up the rest soon.
the permission denied error when running indexmaker comes from omitting one of the backslashes at the end of each line. if you’ve written this to a script as i have, bash is trying to run the next line (after the missing backslash) as a command. as your cmd files are not chmod +x, they won’t run. to resolve, add the necessary backslashes.
I got an error:
Use of uninitialized value in hash element at /usr/bin/indexmaker line 352.
Please help !
this is a wonderful site. BLESSIMO
Hello, everything goes well until i try this:
Make the Index Files
#/usr/bin/indexmaker āoutput=/var/www/mrtg/index.html \
ātitle=āMemory and CPU Usage ā \
āsort=name \
āenumerate \
/etc/mrtg/cpu.cfg \
/etc/mrtg/mem.cfg \
/etc/cron.mrtg/memfree \
/etc/cron.mrtg/mempercent \
/etc/cron.mrtg/disk
i get:
ERROR: unable to open config file: āoutput=/var/www/mrtg/index.html
found the problem: #/usr/bin/indexmaker āoutput=/var/www/mrtg/index.html \ should be: /usr/bin/indexmaker –output=/var/www/mrtg/index.html
lol, this page crams the two dashes together.. –output should have two dashes
For the problem
“Use of uninitialized value in hash element at /usr/bin/indexmaker line 352”
Before do indexmarket you need connect the linux server to the network, and you need make a ping from linux server to other workstation for traffic generation. Try againg cfgmaker , indexmaker and mrtg commands.
Patoflash
Hi all !
When I finished the installation using this guide, after I rebooted my box, I wait for a few minutes and then start the MRTG page… but all I can see is the MRTG-logo which is a link redirecting me to the MRTG website… so I don’t get any graph on my MRTG homepage.
I had no errors during installation.
I also wanted to check the config files for monitoring purposes, but it seems no MRTG map was created in etc/… did I do something wrong ? did I not do something ? did I miss something ?
Thanks for any help anyone can provide š
Ch33rz,
Troma
Hi there,
Tried installing MRTG on Debian Etch with the standard installation instruction. As per the instruction, I think the RunAsDaemon=yes should be set to RunAsDaemon=no. The reason is that if you set RunAsDaemon to yes and put a cron job to run every 5 mins, it will complaint with this message
==> mrtg/mrtg.log <==
ERROR: I Quit! Another copy of mrtg seems to be running. Check /etc/mrtg.pid
Not sure why nobody notice this.
Regards.
should we create the /etc/mrtg/cpu.cfg /mem.cfg /memfree.cfg /mempercent.cfg
/disk.cfg files or they are somewhere already present ? cannot go ahead to monitoring disk, memory and cpu but only traffic analysis ? I am stuck here can anyone help from here ? I guess the tutorial lags proper explanation regarding these, Can anyone help in this matter, I googled for some time but cannot come up with a solution to cpu, disk, memory anylysis.
Thanks in advance.
Get the following error message:
ERROR: I Quit! Another copy of mrtg seems to be running. Check /etc/mrtg.pid
Please Help!
i’ve done everything as it is, but got error, when i tried to add cpu an mem graph.
ERROR: CFG Error Unknown Option “sscpurawnice.0&sscpurawnice.0” on line 5 or above.
Check /usr/share/doc/mrtg/mrtg-reference.txt.gz for Help
It worked with translated textual MIBs to OIDs, PageTop missing H1 error was corrected by specifying PageTop[localhost.cpu]: Active CPU Load % correctly for cpu, mem, memfree and mempercent configuration files, and lastly indexmaker worked by using only *.cfg files (below at the bottom).
Cpu.cfg file
WorkDir: /var/www/mrtg
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
Target[localhost.cpu]:.1.3.6.1.4.1.2021.11.50.0&.1.3.6.1.4.1.2021.11.50.0:[email protected]+ .1.3.6.1.4.1.2021.11.52.0&.1.3.6.1.4.1.2021.11.52.0:[email protected]+.1.3.6.1.4.1.2021.11.51.0&.1.3.6.1.4.1.2021.11.51.0:[email protected]
RouterUptime[localhost.cpu]: [email protected]
MaxBytes[localhost.cpu]: 100
Title[localhost.cpu]: CPU Load
PageTop[localhost.cpu]: Active CPU Load %
Unscaled[localhost.cpu]: ymwd
ShortLegend[localhost.cpu]: %
YLegend[localhost.cpu]: CPU Utilization
Legend1[localhost.cpu]: Active CPU in % (Load)
Legend2[localhost.cpu]:
Legend3[localhost.cpu]:
Legend4[localhost.cpu]:
LegendI[localhost.cpu]: Active
LegendO[localhost.cpu]:
Options[localhost.cpu]: growright,nopercent
Mem.cfg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[localhost.mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.6.0:StayAway@localhost
PageTop[localhost.mem]:Free Memory
WorkDir: /var/www/mrtg
Options[localhost.mem]: nopercent,growright,gauge,noinfo
Title[localhost.mem]: Free Memory
MaxBytes[localhost.mem]: 1000000
kMG[localhost.mem]: k,M,G,T,P,X
YLegend[localhost.mem]: bytes
ShortLegend[localhost.mem]: bytes
LegendI[localhost.mem]: Free Memory:
LegendO[localhost.mem]:
Legend1[localhost.mem]: Free memory, not including swap, in bytes
Memfree.cfg
WorkDir: /var/www/mrtg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[server.memory]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.5.0:StayAway@localhost
Title[server.memory]: Free Memory
PageTop[server.memory]: Free Memory
MaxBytes[server.memory]: 100000000000
ShortLegend[server.memory]: B
YLegend[server.memory]: Bytes
LegendI[server.memory]: Free
LegendO[server.memory]: Total
Legend1[server.memory]: Free memory, not including swap, in bytes
Legend2[server.memory]: Total memory
Options[server.memory]: gauge,growright,nopercent
kMG[server.memory]: k,M,G,T,P,X
Mempercent.cfg
WorkDir: /var/www/mrtg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Title[server.mempercent]: Percentage Free Memory
PageTop[server.mempercent]: Percentage Free Memory
Target[server.mempercent]: (.1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.6.0:StayAway@localhost ) * 100 / (.1.3.6.1.4.1.2021.4.5.0&.1.3.6.1.4.1.2021.4.5.0:StayAway@localhost )
options[server.mempercent]: growright,gauge,transparent,nopercent
Unscaled[server.mempercent]: ymwd
MaxBytes[server.mempercent]: 100
YLegend[server.mempercent]: Memory %
ShortLegend[server.mempercent]: Percent
LegendI[server.mempercent]: Free
LegendO[server.mempercent]: Free
Legend1[server.mempercent]: Percentage Free Memory
Legend2[server.mempercent]: Percentage Free Memory
Make the Index Files
Indexmaker
/usr/bin/indexmaker –output=/var/www/mrtg/index.html \
–title=āMemory, CPU and Bandwidth Usageā \
–sort=name \
–enumerate \
/etc/mrtg/mrtg.cfg \
/etc/mrtg/cpu.cfg \
/etc/mrtg/mem.cfg \
/etc/mrtg/memfree.cfg \
/etc/mrtg/mempercent.cfg
My apology PageTop missing H1 should set up as
PageTop[localhost.cpu]: Active CPU Load % for cpu.cfg
PageTop[localhost.mem]:Free Memory for mem.cfg
PageTop[localhost.memory]: Free Memory for memfree.cfg
PageTop[server.mempercent]: Percentage Free Memory for mempercent.cfg
Thanks guy for the tips and hints you provided. My MRTG now works after about 2 weeks of sleepless nights trying to work out all the troubles and figuring out the errors from apt-get install to compilation. I am now getting graphs from my routers this morning after daemonizing the MRTG. It works perfectly fine. Now for my next project, i will MRTG the Cisco Catalyst.
By the way, i completed all this on Debian….
there is no gcc for ubuntu
i need to run it each time to make mrtg grow
env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
that what is in my
/etc/cron.d/mrtg
*/5 *l * * * root if [ ! -d /var/lock/mrtg ]; then mkdir /var/lock/mrtg; fi; if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ]; then env LANG=C /usr/bin/mrtg /etc/mrtg.cfg 2>&1 | tee -a /var/log/mrtg/mrtg.log ; fi
#
I am trying to install mrtgā¦.i am in the last step in completing the process but when i entered the command..
indexmaker āoutput=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg
it gives the following error.
Use of uninitialized value $first in hash element at /usr/bin/indexmaker line 353.
I searched it on google but i donāt get the proper answer..plz help me out..
Is this guide up to date??
On a fresh installation, I found this comment in /etc/snmp/snmpd.conf
# It’s no longer typically necessary to use the full ‘com2sec/group/access’ configuration
# r[ou]user and r[ow]community, together with suitable views, should cover most requirements
Does this mean that the part regarding “com2sec” in your guide isn’t needed?? There are no occurrences (not even commented) of “com2sec” in that file.
And then:
> #cfgmaker [email protected].0.1 >> /etc/mrtg.cfg
I presume 192.168.0.1 needs to be replaced with the actual router address?
How do I figure out mine?
What does this part mean??
> The configuration file creating using
> #cfgmaker public@localhost > /etc/mrtg.cfg
This is not even a meaningful sentence in English.
It is followed by:
> [title] Creating a configuration file for a device using cfgmaker
> #cfgmaker [email protected].0.1 >> /etc/mrtg.cfg
So are we supposed to write localhost or the router’s IP?