[mrtg-developers] Enhancement to MRTG and 14all.cgi

Schuyler Bishop SBishop at e-xpedient.com
Wed Jul 11 22:26:47 MEST 2001



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



More information about the mrtg-developers mailing list