[mrtg] Re: Reporting Top-10 Usage stats

Rolen, Mark E. MERolen at APACMail.com
Tue Apr 18 17:35:27 MEST 2000

I didn't include the script because it's written to be rather specific to my
MRTG installation, although it should be relatively easy for someone to
tailor (and likely improve as well  :)  ).  I have my MRTG setup with a
Workdir of /www/mrtg, and all of my routers and switches have a directory
within /www/mrtg named after the device.  All the .html for each router or
switch is in that subdirectory (in other words, it doesn't descend any
deeper than the directory named after a device.)  Finally, all of my target
names are the IP address or DNS name of the interface being polled.  So, the
script probably isn't very portable unless your MRTG installation somewhat
resembles this; if yours does, then it may work for you as well.  Here's
what it does (and why it probably isn't too portable).

The script:

Starts in /www/mrtg.
Reads the directory into an array, then tests each element of the array to
see if it is a file or a directory (a directory that doesn't start with a
'.', to be specific).
If the element is a directory, it descends into that directory and looks for
*.html files.
In the html, it finds the second and fifth instances of '(nn.n%)', which are
the daily average in and average out (assuming you have a default mrtg html
Strips those mumbers of extra characters, adds them together, and stores
them in an array along with the device name (the subdirectory it's in) and
the interface address (which is the name of the html file minus the .html,
due to the way I name my targets).
Repeat for all directories in /www/mrtg until I have an array with the
utilization and info for every interface I poll.
Sort that array in reverse numerical order and format/print out the top 10

The code is quite a hack, I'm no programmer, but it works perfectly well for
me.  If, after seeing what it does and what it needs, you're still
interested in it, I'll gladly pass it along.  If your MRTG installation is
close to what I mentioned above, it'll probably work 'right out of the box'
for you, otherwise you'll have to dig around in it a bit.

This is exactly the output that I get emailed to me every day:


The top talkers for 4-17-2000 are...

% Util.     Site                      Interface        
25.9%       alton              
25.0%       gtc-bcn                
24.8%       davenport              
23.8%       gtc-bcn             
17.9%       gtc-bcn                
16.7%       oklahoma1          
16.0%       gtc-bcn                
15.9%       lacrosse               
15.7%       ottumwa            
15.7%       westminster        



It also sends the daily graph for each of the interfaces as an attachment,
but you could comment out the few lines that do that if you didn't want the
graphs too.

Based on the interest I've had from opening my big mouth, I may have to work
on a cleaned up version that would work for a wider array of mrtg
installations and contribute it.

Ah, well, let me know if you're still interested in this one and I'll
forward it along.


Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org

More information about the mrtg mailing list