If you run Linux server, there are times you probably wonder how much traffic is flowing through your server. It could be you got a fat bill from your ISP because you used too much bandwidth (good problem to have most of the time). At that point, you probably want to monitor how much bandwidth you are using. One of the best tools you can use is MRTG (Multi Router Traffic Grapher). It is not very hard to setup MRTG and requires only few packages to be installed.
Assumptions:
- Linux server with Yum installed (of course you can download individual packages in other flavors of Linux which I am not going into details here).
- Your server ip is on 192.x.x.x network. If your server is not, please replace all the places where I mention using 192.x.x.x)
- We are going to store files in /home/vhosts/mrtg If you want a different location, change it in all appropriate places.
- Apache is installed at: /usr/local/apache2/ with httpd.conf in conf directory in Apache installed directory.
- SNMP/MRTG packages are not installed.
- Server IP is 192.168.30.115
- Last but not least, YOU are logged in as root!
Ok now let us go into details on how to install MRTG.
Lets install all the packages we need. Note that this will also install few other packages. Eg. gd, lm_sensors, net-snmp-libs, etc
yum -y install mrtg net-snmp-utils net-snmp
Now lets start SNMP server
/etc/init.d/snmpd start
Is SNMP running? You should see something after you run following command
netstat -na | grep '0.0.0.0:199'
If it is not working, check logs and see why not. If it is (which is most probably the case if you didn’t miss the second step), try this command and see if you get output:
snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
OUTPUT (something similar, your 192.x.x.x ip should be your server ip):
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.192.168.30.115 = INTEGER: 2
If you don’t get the above or something similar output, do following.
NOTE: I had to do following on all the servers I had setup:
vi /etc/snmp/snmpd.conf
Replace the content in there with following:
com2sec local localhost public
com2sec mynetwork 192.0.0.0/8 public
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
view all included .1 80
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
syslocation "Some place out there"
syscontact Admin <[email protected]>
You should change last two lines to something appropriate to your usage.
At this point you should be good to go, so lets restart SNMP.
/etc/init.d/snmpd restart
Run this command look for appropriate output as mentioned above.
snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
Ok. That is all we will do with SNMP. Let us continue our MRTG installation.
Let us set up data directory to store html files:
mkdir /home/vhosts/mrtg
Now let us set up mrtg.conf to use for monitoring bandwidth usage:
cfgmaker --global "workdir: /home/vhosts/mrtg" -ifref=ip --output /etc/mrtg/mrtg.cfg --global 'options[_]: growright,bits' [email protected]
Let us create index file for MRTG page:
indexmaker --output=/home/vhosts/mrtg/index.html /etc/mrtg/mrtg.cfg
It is time for us to tell Apache to serve these pages
vi /usr/local/apache2/conf/httpd.conf
Alias /mrtg /home/vhosts/mrtg
<location /mrtg>
Order deny,allow
Deny from all
Allow from 127.0.0.1 192.168.30.0/24
</location>
NOTE: Make sure your subnet is in “Allow from ” line. Otherwise you won’t be able to access MRTG files from browser.
Restart Apache to read the new conf file.
/usr/local/apache2/bin/apachectl graceful
It is time for us fire this thing up and start creating some graphs!
env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --logging /var/log/mrtg.log
You should be able to view your MRTG graphs at: http://192.168.30.115/mrtg
If everything is working fine, let us add this to cron so these stats are updated every 5 mins.
crontab -e
*/5 * * * * env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --logging /var/log/mrtg.log
mrtg installation
How do you monitor many servers from one _SERVER/mrtg/index.html ?
Thank you very much, i was hitting my head against the wall just now with the snmpd.conf and this worked perfectly!
Thanks a lot for the instructions, worked perfectly. I also managed to have multiple devices in one page with mrtg, basically you have to set up a separate workdir and .cfg file for every device, add the crontab entries and then link all the .html pages in the main .index.html
(or just copy&paste relevant sections from the other index.html pages to the main index.html).
Hi guys…
I got everything done as instructed above… but I got permission problems π
Forbidden
You don’t have permission to access /mrtg/ on this server.
——————————————————————————–
Apache/2.2.3 (CentOS) Server at 192.168.159.11 Port 80
Can someone point me in the right direction? I did make the /home/mrtg folder permissions 755, then 777… to no avail
Kevin,
Make sure below line in httpd.conf includes your own ip:
Allow from 127.0.0.1 192.168.30.0/24
Add it in and restart apache and see if it works.
Hi Sunny,
Thanks! Turns out mrtg is already defined as an alias prior to my alias… which points to a place where apache user cannot access…
I was also able to run cfgmaker couple times with different *.cfg output files, then run indexmaker with those multiple *.cfg files by separating them with space…. turns out MRTG now runs monitoring on all those devices… I feel good π
Hey guys… got another question… quite important for me… I have two ASA5505 being monitored by MRTG right now and they output seem great…
The million dollars question is… how do I monitor the VPN tunnel between them? I just want to measure the traffic on the tunnel.
Appreciate any kind of help… point me to a link would be good enough… been asking Dr. G and he has too many vague answers π Thanks!
Dear Sir,
I have to configure MRTG in linux server please send me the configuration details so that i will configure easily.
Waiting for you reply.
Thanking You
Sunny Walia thanks for your time, I’m learning a lot here.
ps to shamshad: are you kidding?
You are very welcome Alex. If you have any questions, you can post ’em in the forums section and I will try to help as I get a chance π
Dear all,
like the above, i get
Forbidden
You don’t have permission to access /mrtg/ on this server.
Apache/2.2.14 (EL) Server at 127.0.0.1 Port 80
when i put the http://127.0.0.1/mrtg in the browzer.
anyways, my intention is to play around with the configuration of the MRTG in localhost( i mean in my computer)..but no other devices.
Please any one ..help..me
Dear Sunny this is my httpd.conf entry for alias
Order deny,allow
Deny from all
Allow from 127.0.0.1 192.168.7.0/24
Still i am getting following error
Forbidden
You don’t have permission to access /mrtg/ on this server.
Apache/2.2.3 (CentOS) Server at 192.168.7.96 Port 80
Please help me out.
Towhid:
Have you restarted apache since you added allow? Also check your error_log file and see if it has any more details.
You only have to coment one line on /etc/httpd/conf.d/mrtg. You must replace allow 127.0.0.1, with allow any.
Dear sir please send the configuration step by step of MRTG in linux RHCE…Yours response is highy appreciated.
Thank you!!!
Dear sir ,
Please send the configuration step by step of MRTG server in linux
Yours response will be highly appreciated
Thank you..!!!
Is it possible to configure MRTG to show only half the rate of actual rate? if yes, how?
when i enter snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
this command do i have to replace IP with my own ip or not ? one more thing when i enter this command it says
-bash command not found
Literally millions of spores are produced by each mold colony
and discolored streaks result along with clumps of blue,
green, or white furry looking growths on the surface of the cheese.
Even if thereΓ’β¬β’s just a little bit of moisture, the possibility
of mold infestation is high. If you hire a company that handles both processes from the start, they are likely to
be able to discover that mold is going to be a problem and take care of it before it becomes
a health issue.
Howdy! I simply would like to give you a big thumbs
up for your great information you have got right
here on this post. I will be returning to your web site for more soon.
Its like you read my mind! You appear to know so much approximately this, like you wrote the guide in it or something.
I think that you could do with a few percent to power the message
home a bit, but other than that, this is wonderful blog. A great read.
I’ll certainly be back.
Feel free to visit my homepage :: vindictus hack – youtube.com –
I know this website gives quality depending posts and extra stuff,
is there any other web page which presents these kinds of stuff in quality?
My web page … peppermint oil mice review
I like the helpful info you provide in your articles.
I will bookmark your weblog and check again here regularly.
I am quite certain I’ll learn many new stuff right here!
Best of luck for the next!
Feel free to surf to my page – BEST MOUSE BAIT
Pretty nice post. I just stumbled upon your weblog and wanted to say that I’ve really enjoyed surfing around
your blog posts. In any case I will be subscribing
to your feed and I hope you write again very soon!
Also visit my web-site: throne rush hack (Stacie)
In many cases, local companies offer fast and convenient vehicle pickups every
dayy of thee week. The most adventurous thing you can do with a junk vehicle is take off the alternator and use it to
make your own wind mill. Used books can go well wiith a younger crowd, and near cafes and
newsstands.
With probably around five or six films to choose from,
the one he showed on that particular evening was
the quintessential World War Two drama, in glorious black and white, “Sink The Bismark”.
To sail off fast on the new close-hauled course, sheet in the jib and pull the tiller towards you.
You often fail to complete the tack or misjudge the wind when first learning how to
handle a catamaran.
Wow, wonderful blog structure! How long have you been running a blog for?
you made blogging look easy. The full glance of your website is excellent, as smartly as the content material!
Hey there! I know this is somewhat off topic but I was wondering if
you knew where I could find a captcha plugin for my
comment form? I’m using the same blog platform as yours and I’m having trouble finding one?
Thanks a lot!
This dust can enter the house with the air and cause illness and aggravate any dust related allergies.
If you don’t deal with the continual mold issue inside your home or office, the result can be
much worse. When mold is found, a homeowner must contact certified mold remediation companies to find a competent contractor to handle the situation.
my website – Long Island wood prefabricated stairs
Hello, I think your blog might be having browser compatibility issues.
When I look at your blog site in Ie, it looks fine but when opening in Internet Explorer,
it has some overlapping. I just wanted to give you
a quick heads up! Other then that, excellent blog!
I pay a quick visit everyday some blogs and information sites to
read posts, however this weblog offers quality based articles.
It’s nearly impossible to find experienced people on this subject, but you
sound like you know what you’re talking about! Thanks
Hello I am so excited I found your blog, I really found you
by error, while I was looking on Askjeeve for something else, Anyhow I am here now
and would just like to say kudos for a remarkable post and a all round exciting blog (I also love the theme/design), I don’t have time to browse it all at the
minute but I have saved it and also included your RSS feeds,
so when I have time I will be back to read much more, Please do keep up the superb job.
Today i spent 300 dollars for platinium roulette system , i hope that
i will make my first money online
Hurrah, that’s what I was seeking for, what a data! existing here at this weblog, thanks admin of this web page.
com you can find some great games that will amuse for hours.
Place the solid green 6 ball in front of the striped orange 13
ball. It would depend on what kind of material you wanted to get
as a replacement.
If you are interested in topic: earn money online apple chat –
you should read about Bucksflooder first
Thanks to my father who informed me on the topic of this web site, this weblog is actually
awesome.
I in addition to my friends were reviewing the nice ideas from your web site and then immediately I got a terrible feeling I had not expressed respect to the web site owner for those tips. My ladies had been for this reason warmed to study all of them and now have definitely been taking pleasure in those things. Thank you for really being quite considerate and then for picking out variety of essential subject areas millions of individuals are really wanting to know about. My sincere regret for not saying thanks to sooner.
Thank you a lot for providing individuals with an extraordinarily nice opportunity to discover important secrets from this blog. It really is so beneficial and as well , jam-packed with a lot of fun for me and my office peers to visit your blog a minimum of three times every week to read the newest secrets you have. And lastly, I’m also certainly pleased with your powerful things you give. Selected two tips in this article are essentially the finest we have had.