[rrd-users] Re: [mrtg-developers] Enhancement to MRTG and 14all.cgi

Schuyler Bishop SBishop at e-xpedient.com
Thu Jul 12 17:23:27 MEST 2001


Oh - forgot usage!  Duh!

For the yearly mod to MRTG, use --yearly on the command line.  It's only
needed if you need it to create the RRDs, but I keep it in my crontab just
to remind me which ones are yearly.  :)  MRTG will die if your config
doesn't use RRDTool and you specify --yearly on the command line.

For 14all.cgi - there are 5 arguments - in an URL like the following: (your
mileage may vary - I define cfgdir in 14all.cgi and use cfg= to specify a
config)

http://server/14all.cgi?log=1.1.1.1_1&cfg=config.cfg&png=custom&sdate=7-9-20
01&stime=12:00:00&edate=7-9-2001&etime=16:00:00

To do a custom graph:
png=custom is required
sdate=mm-dd-yyyy must be formatted specifically with "-"s - I did the
split() on a "-".  :)
edate=mm-dd-yyyy - same deal.
stime=hh:mm:ss and etime=hh:mm:ss are optional - but if used must be
specifically formatted as above.  If you use either stime or etime, you MUST
use both.  I didn't do THAT much error checking.  :)

Thanks.

Schuyler

-----Original Message-----
From: Schuyler Bishop [mailto:SBishop at e-xpedient.com]
Sent: Wednesday, July 11, 2001 4:27 PM
To: MRTG Developers list (E-mail); MRTG list (E-mail); RRD Users list
(E-mail)
Subject: [mrtg-developers] Enhancement to MRTG and 14all.cgi




Hello, all.

I've made a minor enhancement to MRTG that allows MRTG to log 1 year's worth
of 5-minute intervals for a config.  In addition, I modified 14all.cgi to
allow for a custom date-time PNG graph to be created with inputs from the
CGI.

The modifications to 14all can be used with a stock config from MRTG, using
RRD of course.  I use a simple form with some hidden values to submit info
to 14all.cgi.

I've attached the diff(s) for each below.  If you would like the actual
modified versions I use, e-mail me and I'll send them.  BTW - the 14all is
based on the current revision, and MRTG is 2.9.12a.

Schuyler

For MRTG:

114c114,116
<     GetOptions(\%opts, 'user=s', 'group=s',
'lock-file=s','confcache-file=s');
---
>     # Edited by Schuyler (schuyler at usa.net) to add yearly! ,'yearly!'
>     GetOptions(\%opts, 'user=s', 'group=s',
'lock-file=s','confcache-file=s','yearly!');
>     # End edits
161a164,169
>     
>     # Check to see if yearly is set and rrdtool is not - die if so.
>     # Schuyler - (schuyler at usa.net)
>     if ($cfg{logformat} ne 'rrdtool' and $opts{yearly} = 1) {
>       die "\"--yearly\" is only supported with RRDTool.";
>     }
262c278,280
<                    writegraphics($router, \%cfg, \%rcfg, $inlast,
$outlast, $time,$LOC);
---
>                  # The arguments passed below were modified to add support
for the --yearly option
>                  # by Schuyler (schuyler at usa.net) with $opts{yearly}
>                    writegraphics($router, \%cfg, \%rcfg, $inlast,
$outlast, $time, $LOC, $opts{yearly});
265c283
<                   writegraphics($router, \%cfg, \%rcfg, $inlast, $outlast,
$time,$LOC);
---
>                   writegraphics($router, \%cfg, \%rcfg, $inlast, $outlast,
$time, $LOC, $opts{yearly});
350c371,373
<     my($router, $cfg, $rcfg, $inlast, $outlast, $time,$LOC) = @_;
---
>     # This assignment was modified to have a local variable, $yearly, that
is equivalent
>     # to the global variable, $opts{yearly} by Schuyler (schuyler at usa.net)
>     my($router, $cfg, $rcfg, $inlast, $outlast, $time, $LOC, $yearly) =
@_;
410,427c434,472
<             my $interval = $$cfg{interval} || 5;
<             my $minhb = int($$cfg{interval} * 60)*2;
<             $minhb = 600 if ($minhb <600);
<             my @args = ($rrd, '-b', $time-10, '-s', int($interval * 60),
<                          "DS:ds0:$up_abs:$minhb:0:$absi",
<                          "DS:ds1:$up_abs:$minhb:0:$abso",
<                          "RRA:AVERAGE:0.5:1:600",
<                          "RRA:AVERAGE:0.5:6:700",
<                          "RRA:AVERAGE:0.5:24:775",
<                          "RRA:AVERAGE:0.5:288:797",
<                          "RRA:MAX:0.5:1:600",
<                          "RRA:MAX:0.5:6:700",
<                          "RRA:MAX:0.5:24:775",
<                          "RRA:MAX:0.5:288:797");
<             RRDs::create(@args);
<             my $e = RRDs::error();
<             die "ERROR: Cannot create logfile: $e\n" if $e;
<             debug('log', "Called: RRDs::create(@args)");
---
> 
>           # the if -> else statement below was added by Schuyler
(schuyler at usa.net)
>           # to support the --yearly argument.  All this really does is
create an RRD
>           # that has 105120 5-minute increments if it doesn't already
exist.  Nothing else
>           # is needed to support a year's worth of 5-minute data since RRD
takes care of 
>           # the other "stuff".  --yearly won't do anything without RRDTool
support.
>           if($yearly eq 1){
>               my $interval = $$cfg{interval} || 5;
>                 my $minhb = int($$cfg{interval} * 60)*2;
>                 $minhb = 600 if ($minhb <600);
>                 my @args = ($rrd, '-b', $time-10, '-s', int($interval *
60),
>                              "DS:ds0:$up_abs:$minhb:0:$absi",
>                              "DS:ds1:$up_abs:$minhb:0:$abso",
>                              "RRA:AVERAGE:0.5:1:105120",
>                              "RRA:MAX:0.5:1:105120");
>                 RRDs::create(@args);
>                 my $e = RRDs::error();
>                 die "ERROR: Cannot create logfile: $e\n" if $e;
>                 debug('log', "Called: RRDs::create(@args)");  
>           } else {
>                 my $interval = $$cfg{interval} || 5;
>                 my $minhb = int($$cfg{interval} * 60)*2;
>                 $minhb = 600 if ($minhb <600);
>                 my @args = ($rrd, '-b', $time-10, '-s', int($interval *
60),
>                              "DS:ds0:$up_abs:$minhb:0:$absi",
>                              "DS:ds1:$up_abs:$minhb:0:$abso",
>                              "RRA:AVERAGE:0.5:1:600",
>                              "RRA:AVERAGE:0.5:6:700",
>                              "RRA:AVERAGE:0.5:24:775",
>                              "RRA:AVERAGE:0.5:288:797",
>                              "RRA:MAX:0.5:1:600",
>                              "RRA:MAX:0.5:6:700",
>                              "RRA:MAX:0.5:24:775",
>                              "RRA:MAX:0.5:288:797");
>                 RRDs::create(@args);
>                 my $e = RRDs::error();
>                 die "ERROR: Cannot create logfile: $e\n" if $e;
>                 debug('log', "Called: RRDs::create(@args)");
>           }


14all.cgi:

30a31,33
> # Added by Schuyler for localtime()
> use Time::Local;
> # End Adds
70a74,98
> # Added by Schuyler (schuyler at usa.net) for date range inputting
> # take the parameters sdate and edate and create an array to use for
localtime()
> my @sdate = split(/\-/, $q->param('sdate'));
> my @edate = split(/\-/, $q->param('edate'));
> 
> # If the parameters stime and etime are defined, then use them.  Else, use
midnight for both.
> 
> my @stime;
> my @etime;
> 
> if (defined $q->param('stime')) {
>       @stime = split(/\:/, $q->param('stime'));
>       @etime = split(/\:/, $q->param('etime'));
> } else {
>       @stime = (0, 0, 0);
>       @etime = (0, 0, 0);
> }
> # timelocal() wants a 0-based month.  :(
> $sdate[0] -- ;
> $edate[0] -- ;
> my $starttime = timelocal($stime[2], $stime[1], $stime[0], $sdate[1],
$sdate[0], $sdate[2]);
> my $endtime = timelocal($etime[2], $etime[1], $etime[0], $edate[1],
$edate[0], $edate[2]);
> # End Adds
> 
93,96c121,126
<       'daily'   => ['-2000m', 'now',  300],
<       'weekly'  => ['-12000m','now', 1800],
<       'monthly' => ['-800h', 'now',  7200],
<       'yearly'  => ['-400d', 'now', 86400],
---
>       # Added custom for starttime and endtime - Schuyler
>       'custom'  => [$starttime,$endtime,300],
>       'daily'   => ['-24h', 'now',    300],
>       'weekly'  => ['-7d','now',      300],
>       'monthly' => ['-1m', 'now',     300],
>       'yearly'  => ['-1y', 'now',     300],
97a128,130
>       # Note also that I changed the start values and interval for each
daily, monthly, etc.  This wasn't 
>       # necessary - I just did to to test.  These probably need to be
changed back for "regular" use except
>       # for the addition of custom.
170a204
> 
267c301,303
<       my $pngfile = "${pngdir}${log}-${png}.png";
---
>       # Edited - added $$ to use PID in file so each is different -
Schuyler
>       my $pngfile = "${pngdir}${log}-${png}$$.png";
>       # End Edit
477c513,519
<                       print $q->header(-type => "image/png", -expires =>
"+${maxage}s");
---
>                       # More edits by Schuyler (schuyler at usa.net) - if
it's a custom graph, expire now so the browser
>                       # Gets the current image that's valid
>                       if ($png eq 'custom') {
>                               print $q->header(-type => "image/png",
-expires => "0s");       
>                       } else {
>                               print $q->header(-type => "image/png",
-expires => "+${maxage}s");
>                       }
480a523,525
>                       #Added by Schuyler to keep /tmp clean
>                       unlink $pngfile;
>                       #End add
550c595
<               print $q->h2("'Weekly' graph (30 Minute Average)"),"\n",
---
>               print $q->h2("'Weekly' graph (5 Minute Average)"),"\n",
556c601
<               print $q->h2("'Monthly' graph (2 Hour Average)"),"\n",
---
>               print $q->h2("'Monthly' graph (5 Minute Average)"),"\n",
562c607
<               print $q->h2("'Yearly' graph (1 Day Average)"),"\n",
---
>               print $q->h2("'Yearly' graph (5 Minute Average)"),"\n",

----------------------------------------------------
e-xpedient(SM)
A CAVU, INC Service
Schuyler Bishop
Network Security Engineer
Advanced Technology		Ph: 407-903-2780 
Fax: 978-945-4685  	 	Cell: 407-808-7170
4901 Vineland Rd. #600  	Orlando, FL  32811
sbishop at e-xpedient.com     *  	www.e-xpedient.com



--
Unsubscribe
mailto:mrtg-developers-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:mrtg-developers-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/mrtg-developers

--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-users mailing list