|  | #!/usr/bin/perl
 | 
  
    |  | use warnings;
 | 
  
    |  | use strict;
 | 
  
    |  | #
 | 
  
    |  | # Given the name of a MRTG log file in the current directory, output a PNG
 | 
  
    |  | #
 | 
  
    |  | 
 | 
  
    |  | use CGI ':all';
 | 
  
    |  | use CGI::Carp qw(fatalsToBrowser);
 | 
  
    |  | 
 | 
  
    |  | my $log = param('log');
 | 
  
    |  | if (!defined $log) {
 | 
  
    |  | 	die "No logfile";
 | 
  
    |  | }
 | 
  
    |  | if (! -e $log) {
 | 
  
    |  | 	die "logfile does not exist";
 | 
  
    |  | }
 | 
  
    |  | 
 | 
  
    |  | my $xsize = param('xs') || 700;
 | 
  
    |  | my $ysize = param('ys') || 135;
 | 
  
    |  | my $ylabel = param('ylabel') || 'Bytes per Second';
 | 
  
    |  | my $li = param('li') || 'In';
 | 
  
    |  | my $lo = param('lo') || 'Out';
 | 
  
    |  | 
 | 
  
    |  | # FIXME - calulate the timezone
 | 
  
    |  | my $timezone_offset=39600;
 | 
  
    |  | 
 | 
  
    |  | print "Content-Type: image/png\n\n";
 | 
  
    |  | 
 | 
  
    |  | open( GNUPLOT, "|/usr/bin/gnuplot");
 | 
  
    |  | print GNUPLOT <<EOF;
 | 
  
    |  | 	set terminal png size $xsize,$ysize
 | 
  
    |  | 	set key left top
 | 
  
    |  | 	set grid
 | 
  
    |  | 
 | 
  
    |  | 	set xdata time
 | 
  
    |  | 	set format y "%.0s %c"
 | 
  
    |  | 	set timefmt "%s"
 | 
  
    |  | 	set datafile missing "0"
 | 
  
    |  | 
 | 
  
    |  | #	set title "MRTG from $log"
 | 
  
    |  | #	set xlabel "Time"
 | 
  
    |  | 	set ylabel "$ylabel"
 | 
  
    |  | 
 | 
  
    |  | 	plot "$log" using (\$1+$timezone_offset):4 t '$li' lt rgb 'green' w filledcurves y1=0 , \\
 | 
  
    |  | 		"$log" using (\$1+$timezone_offset):5 t '$lo' lt rgb 'blue' w lines
 | 
  
    |  | EOF
 | 
  
    |  | 
 | 
  
    |  | 
 | 
  
    |  | 
 | 
  
    |  | 
 | 
  
    |  | 
 | 
  
    |  | 
 |