[mrtg] Re: how to make a compact daily view of a set of router interfaces

Ashley M. Kirchner ashley at pcraft.com
Thu Oct 5 22:54:46 MEST 2000


wagner at grz.at wrote:

> Can you give me a Perl example on how to make a compact daily view of a set
> of
> router interfaces like you have done?

    Like Marty replied earlier, it's really a modified version of what
indexmaker makes for you.  Run indexmaker first.  Once you have that initial
index.html page, you can alter it any which way you want since MRTG won't touch
it anymore, not till you re-run indexmaker again.

    I changed the format to have two graphs next to each other.  Added relevant
text, comments and other trinkets.

    Two things I've been asked about recently:
        - how do I get time stamps
        - how do i get the 'server up/down' little image

    How to get timestamps
    ---------------------
      Two ways:
      - First one applies to those running Apache like I am.  You can use the
mod_include feature to read a file's last modified stamp (flastmod).  The
documentation on how to use mod_include is at
http://www.apache.org/docs/mod/mod_include.html

        With Apache SSI: [ <!--#flastmod file="/router/lan0/lan0.html" --> ]


      - Second one applies to anyone running PHP like I am.  I decided to use
PHP's function as opposed to Apache's module because you can't use
server-parsed directives as well as PHP directives within the same file.  By
using PHP, I'm able to, once again, do the same thing: grab the last modified
timestamp from the file:

    With PHP:
    <?
    $time = filemtime('router/lan0/lan0.html');
    echo "[ ".date( "l, d-F-Y H:i:s", $time );
    echo " ]";
    ?>

    This will produce: [ Thursday, 05-October-2000 14:20:41 ]

    Read the documentation on PHP's filemtime() and date() functions from
http://www.php.net/





    How to get (dynamic) graphic
    ----------------------------
    How to get the little (dynamic) graphic that says server up/down, service
ok/fail.  I have four little graphic files:

    alive.gif:    server operating
    dead.gif:     server failure (1 second blink)
    servgood.gif: service ok
    servfail.gif: service failure (1 second blink)

    The reason I did a service one as well was because there may be times where
the machine itself may be up, but the actual service I'm monitoring isn't.  So,
I needed some sort of indication.

    Servers:
    --------
    Believe it or not, I do a very simple 'ping' test to the server to find out
whether it's up or not.  Should I get 100% failure after 5 pings, it's flagged
as down.  Anything else, it's up - even if it's extremely slow (this will
change in the future as I expand the script to account for specific 'ms'
responses).

    Following is part of my ping script that checks for SERVERS being up or
not:
    (NOTE: lines wrapped for legibility)

#!/usr/bin/perl
#
#server1
$ping = `/bin/ping -c1 my-server1.com | /usr/bin/tail -n 1`;
open(SRV1, ">status/SRV1.status");
if ($ping =~ "100\% packet loss") {
  print SRV1 "<IMG SRC=\"/images/dead.gif\" WIDTH=\"110\"     \
        HEIGHT=\"12\" ALT=\"Host Down!\" BORDER=\"0\">";
} else {
  print SRV1 "<IMG SRC=\"/images/alive.gif\" WIDTH=\"110\"    \
        HEIGHT=\"12\" ALT=\"Host Up!\" BORDER=\"0\">";
}
close (SRV1);

    After that runs, I will have a text file SRV1.status that contains a
standard <IMG..> tag in it.  Again, using PHP (or Apache), I can include it in
my index file:

    Width PHP: <? include('status/SRV1.status');
    With Apache's SSI: <!--#include virtual="status/SRV1.status" -->



    Service:
    --------
    Probe the port.  WWW = 80   Since I'm graphing web usage, MRTG has to be
able to fetch data from it.  If that fetch fails, the service is down (even if
it just timed out, indicating a severe flood).  If the fetch succeeds, service
is up and running.


    That's it for today's lesson.  Any questions, fire away.

    AMK4

--
W |
  |  I haven't lost my mind; it's backed up on tape somewhere.
  |____________________________________________________________________
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Ashley M. Kirchner <mailto:ashley at pcraft.com>   .   303.442.6410 x130
  SysAdmin / Websmith                           .     800.441.3873 x130
  Photo Craft Laboratories, Inc.             .        eFax 248.671.0909
  http://www.pcraft.com                  .         3550 Arapahoe Ave #6
  .................. .  .  .     .               Boulder, CO 80303, USA



--
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
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the mrtg mailing list