Bekijk de volledige versie : How-To MRTG bandwidth monitoring utility
Do you want to measure what's going in and what's going out your router? I always did, and after some searching I found a tool to do this and plot it in a graph :)
http://oss.oetiker.ch/mrtg/192.33.92.249_fa4_1-day.png
I found MRTG which is the predecessor of RRDtool, used by the largest internet exchange in the world: Amsterdam Internet Exchange (http://www.ams-ix.net/statistics/)
Now, RRDtool is nice, but it will be too advanced for what we want to do, so in this how-to we'll stick to MRTG which does the job just as well :)
The good thing about this monitor is that it only polls once every 5 minutes, so it uses hardly any CPU and will allow the harddrive to spin down now and then.
Before you begin
You need a proper IPKG setup (e.g. from wengi's how-to).
Also you need to activate the SNMP server in the webadmin interface:
http://i45.tinypic.com/122cjsj.jpg
Set it up like in this screenshot
Furthermore, you need some way to access the generated graphs, this can be done via a samba share or a webserver.
Installing
It's as easy as executing:
ipkg install mrtg
Creating config files
The IPKG package doesn't come with configuration files since they're different for every system!
Before you can generate a config file you NEED to make sure the SNMP server is up and running.
Adjust the workdir to your needs, this workdir should be accessible via samba or a webserver. Also don't forget to create the folder before you assign it.
/opt/bin/cfgmaker --global 'WorkDir: /tmp/mnt/share/mrtg' --global 'RunAsDaemon: Yes' --global 'Options[_]: bits,growright' --output /opt/etc/mrtg.cfg public@localhost
now wait a few seconds while the configuration is being made.
Making a startupscript
vi /opt/etc/init.d/S99mrtg
and paste the code:
#!/bin/sh
if [ -n "`pidof mrtg`" ]; then
killall mrtg 2>/dev/null
fi
/opt/bin/mrtg /opt/etc/mrtg.cfg
save it and make it executable:
chmod +x /opt/etc/init.d/S99mrtg
Starting and monitoring
Just execute
/opt/etc/init.d/S99mrtg
and it should start monitoring.
Now just browse to the folder you put as workdir (either via samba or webserver).
You'll see a few html pages called "localhost_x.html" (where x is a number).
Just open up one of those files and the browser should open a page about a single network interface containing daily, weekly, monthly and yearly graphs.
Usually "eth1" is the WAN port (where the internet goes in) so there you can see all the results for internet usage.
Note that the speeds are displayed in bits per second meaning you have to devide the numbers by 8 to get the bytes per second.
the end :p
I hope you'll have fun monitoring.
some extra: http://wl500g.info/showpost.php?p=205121&postcount=18
kolaCZek made a nice post about some other scripts to monitor cpu load, memory usage and ping :)
Just put the mrtg settings in the mrtg.cfg config file and the bash scripts in /opt/etc/mrtg (like described in the target information)
don't forget to chmod +x /some/file the bash scripts to make them executable
Hi,
Thanks for the info, looks like an interesting and fun addition to my router setup, however a couple of errors must be present (at least, according to me...):
RunAsDeamon: Yes is misspelled, and should be (obviously)
RunAsDaemon: Yes
That is the easy one.
I also get an error when running configmaker at the command "public@localhost". I guess a command is missing.
I also cannot make sense of the final part of your tutorial, where you put some code for speed correction. I can see no obvious location to put in the code; if I paste the code in the mrtg.cfg an error occurs.
I hope you understand the problems I encounter, and give a corrected code!
Thanks in advance
Ecori
Hi,
Thanks for the info, looks like an interesting and fun addition to my router setup, however a couple of errors must be present (at least, according to me...):
RunAsDeamon: Yes is misspelled, and should be (obviously)
RunAsDaemon: Yes
That is the easy one.
I also get an error when running configmaker at the command "public@localhost". I guess a command is missing.
I also cannot make sense of the final part of your tutorial, where you put some code for speed correction. I can see no obvious location to put in the code; if I paste the code in the mrtg.cfg an error occurs.
I hope you understand the problems I encounter, and give a corrected code!
Thanks in advance
Ecori
Yes sorry, fixed that typo!
I made the how-to a bit easier now, there is no more editing of the config file, just the command to create it.
The command should just work fine, be sure you didn't remove any quotation marks while editing the workdir.
Also you MUST enable the SNMP server (that's the public@localhost part), since this program uses it to gather data:)
Thanks,
much easier now, but still contains the typo en deamon - daemon. Indeed SNMP was activated, but the router was not rebooted.
Install worked fine now, waiting for the results. Process is running as indicated by ps axf. :)
Regards,
Ecori
Thanks,
much easier now, but still contains the typo en deamon - daemon. Indeed SNMP was activated, but the router was not rebooted.
Install worked fine now, waiting for the results. Process is running as indicated by ps axf. :)
Regards,
Ecori
good good:)
My graphs usually only show spikes, because they are a lot bigger than the usual internet usage.
But the weekly and monthly graphs look quite nice;)
Well, everything seems to be working great. Nice graphs, good overview. What I miss though is the total amount of traffic, what is the amount uploaded and downloaded in a day, week or month. Would be interested to see the total amount of traffic. Since this tool records the traffic activity during the day, can't we use it also for that purpose?
Regards,
Ecori
Well, everything seems to be working great. Nice graphs, good overview. What I miss though is the total amount of traffic, what is the amount uploaded and downloaded in a day, week or month. Would be interested to see the total amount of traffic. Since this tool records the traffic activity during the day, can't we use it also for that purpose?
Regards,
Ecori
Yes, that's one of the downsides I guess.
I found this very short article on the MRTG documentation: http://oss.oetiker.ch/mrtg/doc/mrtg-traffic-sum.en.html
it should make a summary for 1 month... so I guess that might contain the total amount of bandwidth used:p
Thanks!
Once, I gave it a try to do it myself, but didn't work.
This works like a dream!
bebef_1987
04-02-2010, 01:05
How can I use vlan1?
How can I use vlan1?
if it doesn't appear in the HTML files you need to uncomment it.
mrtg automatically filters out interfaces that do not return any speed. This is a problem of the build-in SNMP server and a bit thanks to the kernel as well. The problem is partially fixed thanks to lly: http://code.google.com/p/wl500g/issues/detail?id=78&can=1&colspec=ID%20Type%20Status%20Priority%20Owner%20Su mmary%20Opened
BUT you can comment out an interface in the config yourself, not sure if everything will go allright that way:p
vi /opt/etc/mrtg.cfg
a bit after where it says "System", "Description", "Contact" and "Location" you'll see all the network interfaces listed by the automatic configuration tool.
you just need to scroll down and find your vlan
it probably says:
### The following interface is commented out because:
### * has a speed of 0 which makes no sense
Just remove all the # from where it says "Target" to the very last "</div>" belonging to that interface.
Save it and restart mrtg:
/opt/etc/init.d/S99mrtg
I hope that works:)
bebef_1987
04-02-2010, 23:12
i'v uncomented the interface last night and it worked but on my router (wl500gp-v2) the WAN interface is Vlan1 as i see it. At least this is the interface with the extranet ip. so i shoud use this interface or one of the other ones...
P.S. sry for my english it is a little rusty
i'v uncomented the interface last night and it worked but on my router (wl500gp-v2) the WAN interface is Vlan1 as i see it. At least this is the interface with the extranet ip. so i shoud use this interface or one of the other ones...
P.S. sry for my english it is a little rusty
yeh, vlan1 should be ok when you don't use auto dhcp or static ip for the WAN side:)
bebef_1987
05-02-2010, 02:46
and if i use static witch interface shoud i use?
and if i use static witch interface shoud i use?
then eth1 should be the one as far as I know;)
it has the WAN ip over here, so I guess that's the right one:)
andrewak
05-03-2010, 14:57
and it should start monitoring.
Now just browse to the folder you put as workdir (either via samba or webserver).
You'll see a few html pages called "localhost_x.html" (where x is a number).
Can't find .html files. In the specified directory appeared three files:
mrtg-l.png
mrtg-m.png
mrtg-r.png
and no one .html
In /opt/etc/mrtg.cfg (which was left 'as-is' after creation) have two uncommented interfaces - eth0, eth1
Processes snmpd and mrtg are running.
Any sudgessions how to check what's wrong?
May be I've not installed some additional libraryes? Can you paste here output of 'ipkg list_installed' from your router?
Can't find .html files. In the specified directory appeared three files:
mrtg-l.png
mrtg-m.png
mrtg-r.png
and no one .html
In /opt/etc/mrtg.cfg (which was left 'as-is' after creation) have two uncommented interfaces - eth0, eth1
Processes snmpd and mrtg are running.
Any sudgessions how to check what's wrong?
May be I've not installed some additional libraryes? Can you paste here output of 'ipkg list_installed' from your router?
hmm, are you sure mrtg has enough rights to write to that directory?
how long did you wait before checking? it might take 5 minutes:)
andrewak
05-03-2010, 17:18
hmm, are you sure mrtg has enough rights to write to that directory?
I hope Yes:-)) - mrtg did write three files there. And I did chmod a+w
how long did you wait before checking? it might take 5 minutes:)
I was absent for more then hour - nothing new:-((
SOLVED
Commented string 'RunAsDaemon: Yes' in config and started from terminal - it told me what it need - libjpeg & fontconfig packages
SOLVED
Anyway thank You for attention
ONE MORE TIP (I've spend some time to overcome)
When your uncommenting some interface in mrtg.cfg you MUST remove '#' sign and following SPACE simbol. String '_Target[localhost .....' will be ignored by mrtg
kolaCZek
28-07-2010, 07:28
Some interesting MRTG settings and scripts...
CPU
http://img841.imageshack.us/img841/584/cpuu.png
MRTG settings
Target[cpu]: `/opt/etc/mrtg/cpu.sh`
MaxBytes[cpu]: 500
Title[cpu]: server CPU Load (5 minute average)
YLegend[cpu]: Load*100
ShortLegend[cpu]: load
Legend1[cpu]: CPU Load (x 100)
Legend2[cpu]:
LegendI[cpu]: 1min load
LegendO[cpu]: 5min load
PageTop[cpu]: server 5-minute average CPU Load
Options[cpu]: gauge,nopercent,integer,growright
cpu.sh
#!/bin/sh
awk </proc/loadavg '{print (100*$1) "\n" (100*$2) }'
hostname;
echo "loadavg";
Memory
http://img823.imageshack.us/img823/7047/memoryu.png
(blue - RAM, green - Swap)
MRTG settings
Target[memory]: `/opt/etc/mrtg/memory.sh`
Title[memory]: Mem and Swap Usage
PageTop[memory]: <h1>Memory and Swap Usage</h1>
MaxBytes[memory]: 100000000000
ShortLegend[memory]: B
YLegend[memory]: Memory
LegendI[memory]: Swap
LegendO[memory]: Mem
Legend1[memory]: Swap
Legend2[memory]: Mem
Options[memory]: gauge,growright,nopercent
memory.sh
#!/bin/sh
/usr/bin/free | awk '\
NR==2 {ramUsed = $3 * 1000 }\
NR==3 {swapUsed = $3 * 1000 }\
END { print swapUsed "\n" ramUsed "\n0\n0" }'
Ping
http://img196.imageshack.us/img196/2705/pingbo.png
MRTG settings
Title[ping]: RTT to google.com
PageTop[ping]: <H1>Round Trip Time</H1>
Target[ping]: `/opt/etc/mrtg/ping.sh`
MaxBytes[ping]: 2000
Options[ping]: growright,unknaszero,nopercent,gauge
LegendI[ping]: Pkt loss %
LegendO[ping]: Avg RTT
YLegend[ping]: RTT (ms)
ping.sh
#!/bin/sh
PING="/bin/ping"
ADDR="google.com"
DATA=`$PING -c10 $ADDR -q `
LOSS=`echo $DATA | awk '{print $18 }' | tr -d %`
echo $LOSS
if [ $LOSS = 100 ];
then echo 0
else
echo $DATA | awk -F/ '{print $5 }'
fi
/opt usage
http://img641.imageshack.us/img641/7592/dfopt.png
MRTG settings
Target[df_opt]: `/opt/etc/mrtg/df_opt.sh`
Title[df_opt]: /opt usage
PageTop[df_opt]: <h1>/opt usage</h1>
MaxBytes[df_opt]: 100000000000
ShortLegend[df_opt]: M
YLegend[df_opt]: /opt
LegendI[df_opt]: Free
LegendO[df_opt]: Used
Legend1[df_opt]: Free
Legend2[df_opt]: Used
Options[df_opt]: gauge,growright,nopercent
df_opt.sh
#!/bin/sh
/bin/df | awk '\
NR==5 {used = $2 / 1024}\
NR==5 {free = $3 / 1024}\
END { print free "\n" used "\n0\n0" }'
/tmp/harddisk usage
http://img717.imageshack.us/img717/6034/dfharddisk.png
MRTG settings
Target[df_harddisk]: `/opt/etc/mrtg/df_harddisk.sh`
Title[df_harddisk]: /tmp/harddisk usage
PageTop[df_harddisk]: <h1>/tmp/harddisk usage</h1>
MaxBytes[df_harddisk]: 100000000000
ShortLegend[df_harddisk]: M
YLegend[df_harddisk]: /tmp/harddisk
LegendI[df_harddisk]: Free
LegendO[df_harddisk]: Used
Legend1[df_harddisk]: Free
Legend2[df_harddisk]: Used
Options[df_harddisk]: gauge,growright,nopercent
df_harddisk.sh
#!/bin/sh
/bin/df | awk '\
NR==7 {used = $2 / 1024}\
NR==7 {free = $3 / 1024}\
END { print free "\n" used "\n0\n0" }'
Very nice post kolaCZek!
they all work very well:)
Just a note for the memory script: it shows that I'm using 124kb, but according to free that is supposed to be in megabytes:p
bigphantom
12-12-2010, 10:45
Can't find .html files. In the specified directory appeared three files:
mrtg-l.png
mrtg-m.png
mrtg-r.png
and no one .html
In /opt/etc/mrtg.cfg (which was left 'as-is' after creation) have two uncommented interfaces - eth0, eth1
Processes snmpd and mrtg are running.
i have a similarly problem, i get the 3 files from above and no html. (i waited, restart router several times and after several 10 minute period and still no html)
SNMP running
[admin@rtn root]$ pss | grep snmpd
559 pts/0 S+ 0:00 \_ grep snmpd
215 ? S 0:00 snmpd -c /tmp/snmpd.conf
MRTG running
[admin@rtn root]$ pss | grep mrtg
561 pts/0 S+ 0:00 \_ grep mrtg
rights for mrtg folder
[admin@rtn root]$ ls -la /mnt/www/
total 20
drwxr--r-- 4 admin root 4096 Dec 12 10:51 .
drwxr--r-- 5 admin root 4096 Dec 11 21:40 ..
drwxr-xr-x 3 admin root 4096 Dec 11 23:32 cgi-bin
-rwxrw-rw- 1 admin root 28 Dec 11 18:28 index.php
drwxr-xr-x 2 admin root 4096 Dec 12 11:05 mrtg
my mrtg.cfg file is:
/mnt/www/mtg - indicated by me because I have lighttpd & samba shares in place. I could not see the interfaces to uncomment ! What do i miss ?
# Created by
# /opt/bin/cfgmaker --global "WorkDir: /mnt/www/mrtg" --global "RunAsDaemon: Yes" --global "Options[_]: bits,growright" --output /opt/etc/mrtg.cfg public@localhost
### Global Config Options
# for UNIX
# WorkDir: /home/http/mrtg
# or for NT
# WorkDir: c:\mrtgdata
### Global Defaults
# to get bits instead of bytes and graphs growing to the right
# Options[_]: growright, bits
EnableIPv6: no
WorkDir: /mnt/www/mrtg
RunAsDaemon: Yes
Options[_]: bits,growright
################################################## ####################
# System:
# Description:
# Contact:
# Location:
################################################## ####################
SOLVED
Commented string 'RunAsDaemon: Yes' in config and started from terminal - it told me what it need - libjpeg & packages
1) I've tried with this, but my ipkg says the 2 packs above are installed and up to date (I ran ipkg update first).
2) i killed the mrtg daemon and started it manually. I get this:
[admin@rtn root]$ /opt/etc/init.d/S99mrtg
Segmentation fault
Daemonizing MRTG ...
[admin@rtn root]$ pss | grep mrtg
579 pts/0 S+ 0:00 \_ grep mrtg
577 ? Ss 0:00 /opt/bin/perl -w /opt/bin/mrtg /opt/etc/mrtg.cfg
andrewak
12-12-2010, 13:42
Unfortunately I've stopped to use mrtg because of hi processor load, but as I remember I can suggest
my mrtg.cfg file is:
/mnt/www/mtg - indicated by me because I have lighttpd & samba shares in place. I could not see the interfaces to uncomment ! What do i miss ?
First of all stop mrtg, then rename or remove your mrgt.cfg (as if it just empty) and run:
/opt/bin/cfgmaker --global "WorkDir: /opt/share/www/mrtg" --global "RunAsDaemon: Yes" --global "Interval: 5" --global "Options[_]: bits,growright" --output /opt/etc/mrtg.cfg public@localhost
with Your WorkDir.
This must create new mrtg.cfg with such sections:
### Interface 1 >> Descr: 'lo' | Name: '' | Ip: '127.0.0.1' | Eth: '' ###
### The following interface is commented out because:
### * it is a Software Loopback interface
#
# Target[localhost_1]: 1:public@localhost:
# SetEnv[localhost_1]: MRTG_INT_IP="127.0.0.1" MRTG_INT_DESCR="lo"
# MaxBytes[localhost_1]: 1250000
# Title[localhost_1]: Traffic Analysis for 1 -- noone-gateway
# PageTop[localhost_1]: <h1>Traffic Analysis for 1 -- noone-gateway</h1>
# <div id="sysdetails">
# <table>
# <tr>
# <td>System:</td>
# <td>noone-gateway in Unknown</td>
# </tr>
# <tr>
# <td>Maintainer:</td>
# <td>Administrator</td>
# </tr>
# <tr>
# <td>Description:</td>
# <td>lo </td>
# </tr>
# <tr>
# <td>ifType:</td>
# <td>softwareLoopback (24)</td>
# </tr>
# <tr>
# <td>ifName:</td>
# <td></td>
# </tr>
# <tr>
# <td>Max Speed:</td>
# <td>10.0 Mbits/s</td>
# </tr>
# <tr>
# <td>Ip:</td>
# <td>127.0.0.1 (localhost.localdomain)</td>
# </tr>
# </table>
# </div>
This is what you need to uncomment (not all, but what you need).
Like this - remember that you need to remove leading spaces too:
Target[localhost_4]: 4:public@localhost:
SetEnv[localhost_4]: MRTG_INT_IP="" MRTG_INT_DESCR="eth1"
MaxBytes[localhost_4]: 1250000
Title[localhost_4]: Traffic Analysis for 4 -- noone-gateway
PageTop[localhost_4]: <h1>Traffic Analysis for 4 -- noone-gateway</h1>
<div id="sysdetails">
<table>
<tr>
<td>System:</td>
<td>noone-gateway in Unknown</td>
</tr>
<tr>
<td>Maintainer:</td>
<td>Administrator</td>
</tr>
<tr>
<td>Description:</td>
<td>eth1 </td>
</tr>
<tr>
<td>ifType:</td>
<td>ethernetCsmacd (6)</td>
</tr>
<tr>
<td>ifName:</td>
<td></td>
</tr>
<tr>
<td>Max Speed:</td>
<td>10.0 Mbits/s</td>
</tr>
</table>
</div>
1) I've tried with this, but my ipkg says the 2 packs above are installed and up to date (I ran ipkg update first).
Then you must comment line:
#RunAsDaemon: Yes
in your mrtg.cfg and run
/opt/bin/mrtg /opt/etc/mrtg.cfg
you will see the whole process, But I think that your main problem is that you have no interfaces in mrtg.cfg
2) i killed the mrtg daemon and started it manually. I get this:
[admin@rtn root]$ /opt/etc/init.d/S99mrtg
Segmentation fault
Daemonizing MRTG ...
[admin@rtn root]$ pss | grep mrtg
579 pts/0 S+ 0:00 \_ grep mrtg
577 ? Ss 0:00 /opt/bin/perl -w /opt/bin/mrtg /opt/etc/mrtg.cfg
I think that "Segmentation fault" mean that you shell check (with fsck) your harddisk - I've did it on my linux desktop.
rumenchooo
10-03-2011, 19:28
Simply perfect.
Working like a charm.:D:D:D
Cpu load is acceptable.
Thank you wpte.
Regards
Rumen