Monitor Linux routers and firewalls with MRTG

Daily Newsletters

Sign up to ZDNet UK's daily newsletter.

The basic configuration file will look something like this: Target[192.168.66.72.1]: 1:c1sc0@192.168.66.72 MaxBytes[192.168.66.72.1]: 1250000 Title[192.168.66.72.1]: RTR2: Ethernet0/0 PageTop[192.168.66.72.1]: Traffic Analysis for Ethernet0/0 These are just a few of the many options that can be placed into the MRTG configuration file. The first value here is Target. Inside the brackets is a unique name that will allow separate options for multiple devices and interfaces. Then, we have what will actually be providing the data, in this case, SNMP. Next, we have the MaxBytes option. This is how the upper end is configured, and it's what percentage values are based on. It will vary between mediums and targets, depending on what you are polling. The next two options are for the HTML and act as descriptors. Local scripts provide another way to get information to MRTG. These can range from simple to complex shell and Perl scripts. We'll look at how to do a simple shell script that will provide MRTG with data on packets inbound to an iptables firewall. First, we will create the script, /usr/local/mrtg/iptables-in: #!/bin/bash IPTABLES="/sbin/iptables" UPTIME="/usr/bin/uptime" $IPTABLES -nvxL | grep INPUT | awk '{ print $5 }' $UPTIME | awk '{ print $3, $4, $5 }' This script will pull the number of packets it has accepted from the INPUT rule. It uses grep to search for the line containing INPUT and prints only the fifth value, which in this case is the number of packets processed. The uptime command is used so that MRTG will know how much time has passed between each value and can chart it over a period of time. The mrtg.cfg will then look something like this:
WorkDir: /var/www/mrtg Target[in_packets]: '/usr/local/mrtg/iptables-in' MaxBytes[in_packets]: 1500 Title[in_packets]: Inbound packets PageTop[in_packets]: Inbound Packet Stats This is similar to the configuration used for SNMP above; however, we are pointing the target to an external script called iptables-in. We are also setting a fairly arbitrary MaxBytes setting since we are dealing with packets as opposed to bits or bytes. This will vary from system to system and a few different values may need to be tried. Although this is a rather simple example, it should give you an idea of what is possible with MRTG. Any data you can gather via the command line can be imported into MRTG and graphed in real time. Running MRTG Once MRTG has been installed successfully, you will need to configure it to run on your system. MRTG can be run manually as follows: /usr/bin/mrtg  /etc/mrtg.cfg MRTG updates its log files every time it is run. The first two times, all the files will not have been created and you may see errors. These can be ignored, but anything you see on the third time around will probably warrant closer investigation. It is a good idea to configure cron to run the program, as MRTG will need to execute often to poll devices and gather data. The standard interval is five minutes, but you can change it to fit your particular needs. Place an entry in /etc/crontab giving the interval, user to run as, path to mrtg, and the path to mrtg.cfg like this:
*/5 * * * *  root  /usr/bin/mrtg  /etc/mrtg.cfg Once MRTG is configured and running, all you will need to do is access the pages through a Web browser. You may want to tweak the HTML manually to do such things as index multiple devices and enable auto-refresh. Summary MRTG is a powerful and extensible tool that will allow you to graph network links and system information over a configurable period of time. Utilizing SNMP, local scripts, or a combination of the two, MRTG allows you to easily monitor your devices. Such things as trends, traffic spikes, and slow periods are easy to detect with a visual representation. MRTG does this in excellent form, outputting data in HTML and PNG formats viewable through a Web browser. MRTG doesn't have all the bells and whistles of commercial monitoring software, but it does the job well and is definitely worth considering as part of your network monitoring activities.
Have your say instantly in the
Tech Update forum. Find out what's where in the new Tech Update with our
Guided Tour. Let the editors know what you think in the
Mailroom.

Talkback

ur concept is good.
please give examples with ur concepts
thank u

via Facebook 23 December, 2005 10:27
Reply

Post your comment

In order to post a comment you need to be registered and logged in.

You can also log in with Facebook. Log in or create your ZDNet UK account below

  • Login

Will not be displayed with your comment

By signing up for this service, you indicate that you agree to our Terms and Conditions and have read and understood our Privacy Policy. Questions about membership? Find the answers in the Community FAQ

Get ZDNet UK's daily newsletter

Enter your email address to sign up

ZDNet UK Live

BrownieBoy

> I'm told it's somewhat annoying when people have their Macs stolen > and Apple stores treat the thief as the owner, but there you go. Ouch,...

14 minutes ago by BrownieBoy on AMD Ultrathins to challenge Intel Ultrabooks
Moley

@kevinmchapman. OK, I acknowledge that 'most' was a gratuitous throwaway comment as an afterthought and too presumptuous. As to proof, as you...

5 hours ago by Moley on A tale of two distros: Ubuntu and Linux Mint
Jack Schofield

@BrownieBoy > Works really well for thieves.... >> Nice attempt to deflect the argument by tossing in a point that's totally >> irrelevant, even...

6 hours ago by Jack Schofield on AMD Ultrathins to challenge Intel Ultrabooks
raskolnikof

fantastic that the so called piracy bills have been withdrawn. however, these anti-democracy supporters are still in the shadows so lets be alert...

7 hours ago by raskolnikof on SOPA, Protect IP support wavers in face of online protest
Tony Douglas

Please God no; teach them anything you like - thinking rationally, the uses and misuses of data, what data is and what it's not - but leave the...

9 hours ago by Tony Douglas via Facebook on Kids are the future. Teach ’em to code.
BrownieBoy

@Jack, > Works really well for thieves.... Nice attempt to deflect the argument by tossing in a point that's totally irrelevant, even it were...

23 hours ago by BrownieBoy on AMD Ultrathins to challenge Intel Ultrabooks
bootlegger

Make that 13 people now - I got refused today at Manchester airport. I thought I was up to date on this legislation - I knew of the EU ruling from...

1 day ago by bootlegger on UK airport body scans will not be opt out
tinycg

Don't forget to check out apps like GoodReader or SlideShark either, they're indispensible for people on the go in presentation situations. Best...

1 day ago by tinycg on Four top iPad apps for people on the move
TerryRK

Well it seems there is something a number of us agree on. Why is the Ubuntu Unity launcher so ugly? I thought perhaps it was something to do with...

1 day ago by TerryRK on A tale of two distros: Ubuntu and Linux Mint
Freebies202

Duplicate comments are not made intentionally. Its very good to know that now you are keeping check on this problem because sometimes a commenter...

2 days ago by Freebies202 on Microsoft fixes blog comments, speeds up blogs with open source
kevinmchapman

"the very significant number of users" and "many (most) of us" - you have no evidence for these statements. It is a fact that most users are saying...

2 days ago by kevinmchapman on A tale of two distros: Ubuntu and Linux Mint
Marg Menzies Harrison

Another grammar faux pas is the improper use of "you". When sitting down down in a restaurant, for example, I get cringe when the waitress...

2 days ago by Marg Menzies Harrison via Facebook on 10 flagrant grammar mistakes that make you look stupid
zdnetukuser

And NOW, folks, for Canonical's next trick... Kubuntu is late. Here's a pencil. Draw your own conclusions. cf.:...

2 days ago by zdnetukuser on Linux Minterface
Moley

@kevinmchapman. The discussion here reflects the very significant number of users who really do like the traditional menu system and who wish to...

2 days ago by Moley on A tale of two distros: Ubuntu and Linux Mint
kevinmchapman

Er, no... It is an efficient means of finding the application/file/setting you need in one place. The icons are a simply a fallback for when you...

2 days ago by kevinmchapman on A tale of two distros: Ubuntu and Linux Mint
TerryRK

Isn't the provision of a text based search an admission by the developers that the mass of icons approach does not work? I don't need to use a...

2 days ago by TerryRK on A tale of two distros: Ubuntu and Linux Mint
kevinmchapman

"Unity and GNOME 3 both abandon the old text-based cascading menus in favour of a graphical icon-driven system." Point truly missed. Both use a...

2 days ago by kevinmchapman on A tale of two distros: Ubuntu and Linux Mint
TerryRK

whs001 - Thank you, I'm glad you liked the article. I absolutely agree with you on your first point. I should perhaps have made it clearer that...

2 days ago by TerryRK on A tale of two distros: Ubuntu and Linux Mint
Dennis Nilsson

If we allow corporate interest to dictate the way our government circumvents due process against foreign entities then we should accept the same...

2 days ago by Dennis Nilsson via Facebook on ACTA stumbles in Germany
GHar123

I totally dislike pirating of works, I fear that artists will be deterred from creating works if they think that they are going to get ripped off....

3 days ago by GHar123 on ACTA stumbles in Germany