#!/usr/bin/perl # # code taken from this page: # http://oreilly.com/openbook/cgi/ch06_04.html # # ------------------------------------------------------ $nsamples = 72; # number of x-axis values in my graph $maxok=75; # Ok values are between 0 and this value $maxwarn=200; # Warning values are between $maxok and this value $webmaster = "jose\@nic-nac-project\.de"; $gnuplot = "/usr/bin/gnuplot"; $ppmtogif = "/usr/bin/ppmtogif"; $real_log = "sqlprau.log"; $process_id = $$; $output_ppm = join ("", "temp_", $process_id, ".ppm"); $datafile = join ("", "temp_", $process_id, ".txt"); $access_log = join ("", "temp_", $process_id, ".log"); $x = 0.8; $y = 0.6; $color = 1; $ncrit = 0; $nwarn = 0; $nok = 0; $ymax = 0; system ("tail -$nsamples $real_log > $access_log 2> /dev/null"); if ( open (FILE, "<" . $access_log) ) { for ($loop=0; $loop < $nsamples; $loop++) { $time[$loop] = 0; } $i = 0; while () { if ($i >= $nsamples) { goto breakloop } ; if (m|(.*) - (.*) - ([0-9]*)|) { $time[$nsamples - $i] = $3; if ($time[$nsamples - $i] > $maxwarn) { $ncrit++; } else { if ($time[$nsamples - $i] > $maxok) { $nwarn++; } else { $nok++; } } if ($time[$nsamples - $i] > $ymax) { $ymax = $time[$nsamples - $i]; } $i++; } } breakloop: close (FILE); &create_output_file(); } else { &return_error(500, "Server Log File Error", "Cannot open input data file."); } exit(0); sub create_output_file { local ($loop); if ( (open (FILE, ">" . $datafile)) ) { for ($loop=0; $loop < $nsamples; $loop++) { print FILE $loop, " ", $time[$loop], "\n"; } close (FILE); &send_data_to_gnuplot(); } else { &return_error (500, "Server Log File Error", "Cannot write to data file!"); } } sub send_data_to_gnuplot { my $period = 10; my $xhours = ($nsamples * 10 / 60); open (GNUPLOT, "|$gnuplot"); print GNUPLOT < /dev/null"); unlink $output_ppm, $datafile, $access_log ; }