--- 14all/14all.cgi Mon Jan 6 02:40:32 2003 +++ /home/rafan/www/mrtg-csie/14all.cgi Tue Jan 11 19:02:59 2005 @@ -11,7 +11,7 @@ # if MRTG_lib.pm (from mrtg) is not in the module search path (@INC) # uncomment the following line and change the path appropriatly: -use lib qw(/usr/local/mrtg-2/lib/mrtg2); +#use lib qw(/usr/local/mrtg-2/lib/mrtg2); # if RRDs (rrdtool perl module) is not in the module search path (@INC) # uncomment the following line and change the path appropriatly @@ -32,6 +32,8 @@ BEGIN { eval { require CGI::Carp; import CGI::Carp qw/fatalsToBrowser/ } if $^O !~ m/Win/i }; use MRTG_lib "2.090003"; +use Time::Local; +use POSIX qw(strftime); sub main(); sub set_graph_params($$$$); @@ -99,7 +101,7 @@ 'weekly' => ['-12000m','now', 1800], 'monthly' => ['-800h', 'now', 7200], 'yearly' => ['-400d', 'now', 86400], - 'daily.s' => ['-1250m', 'now', 300], + 'daily.s' => ['-2000m', 'now', 300], ); # the footer we print on every page @@ -276,9 +278,38 @@ } ($start, $end, $maxage) = @{$graphparams{$png}}; } + + my @t = localtime(time); + $t[0] = $t[1] = $t[2] = 0; + my $seconds; + my $oldsec; + + # strftime(3) compatibility test + my $percent_h = '%-H'; + $percent_h = '%H' if (strftime('%-H', gmtime(0)) !~ /^\d+$/); + my $xgrid; + if ($png eq 'daily' || $png eq 'daily.s') { + $seconds = timelocal(@t); + $oldsec = $seconds - 86400; + $xgrid = 'HOUR:1:HOUR:6:HOUR:2:0:' . $percent_h; + } elsif ($png eq 'weekly') { + $seconds = timelocal(@t); + $t[6] = ($t[6]+6) % 7; + $seconds -= $t[6]*86400; + $oldsec = $seconds - 7*86400; + } elsif ($png eq 'monthly') { + $t[3] = 1; + $seconds = timelocal(@t); + $oldsec = $seconds - 30*86400; + } elsif ($png eq 'yearly') { + $t[3] = 1; + $t[4] = 0; + $seconds = timelocal(@t); + $oldsec = $seconds - 365*86400; # FIXME (the right # of days!!) + } my ($xs, $ys); if ($small) { - ($xs, $ys) = (250, 100); + ($xs, $ys) = (400, 100); ($xs, $ys) = ($cfg->{targets}{'14all*indexgraphsize'}{$log} =~ m/(\d+)[,\s]+(\d+)/) if $cfg->{targets}{'14all*indexgraphsize'}{$log}; } else { @@ -325,6 +356,14 @@ $factor *= 0+$cfg->{targets}{factor}{$log}; } + # vrule + push @args, "VRULE:$oldsec#ff0000"; + push @args, "VRULE:$seconds#ff0000"; + + if ($xgrid) { + push @args, '-x', $xgrid; + } + # check if only one value should be graphed (set vars for fast access) my $noi = $cfg->{targets}{options}{noi}{$log}; my $noo = $cfg->{targets}{options}{noo}{$log}; @@ -404,10 +443,10 @@ } elsif (yesorno($cfg->{targets}{'14all*logarithmic'}{$log})) { push @args, '-o'; } - push @args,'--alt-y-mrtg','--lazy','-c','MGRID#ee0000','-c','GRID#000000'; + push @args,'--alt-y-mrtg','--lazy'; # contributed by Henry Chen: option to stack the two values # set the mode of the second line from config - my $line2 = 'LINE1:'; + my $line2 = 'LINEM:'; if (yesorno($cfg->{targets}{'14all*stackgraph'}{$log})) { $line2 = 'STACK:'; } @@ -646,7 +685,7 @@ # the header lines and tags for the graphics my $pngdir = getdirwriteable($cfg->{config}{imagedir}, $cfg->{targets}{directory}{$log}); if ($sup !~ /d/) { - print $q->h2("'Daily' graph (5 Minute Average)"),"\n", + print $q->h2("'Daily' graph ($cfg->{config}{interval} Minute Average)"),"\n", $q->img({src => "$url=daily", alt => "daily-graph", getpngsize("$pngdir$log-daily.png")} ), "\n";