Revision 3535716b
Added by Hamish Coleman over 17 years ago
- ID 3535716ba15d0e014fd9b07d8130438d7ebde5d2
| gnuplot-mrtg | ||
|---|---|---|
|
#!/bin/bash
|
||
|
#
|
||
|
# given a list of MRTG nrproc files, plot the loadavg
|
||
|
#
|
||
|
|
||
|
if [ -z "$1" ]; then
|
||
|
echo need a mrtg file
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
if [ ! -f $1 ]; then
|
||
|
echo file $1 does not exist
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
TIMEOFFSET=39600
|
||
|
|
||
|
TEMPFILE=`tempfile`
|
||
|
(
|
||
|
cat <<EOF
|
||
|
set terminal png size 700,135
|
||
|
|
||
|
set mouse clipboardformat 5
|
||
|
set mouse mouseformat 5
|
||
|
set xdata time
|
||
|
set timefmt "%s"
|
||
|
set datafile missing "0"
|
||
|
set grid
|
||
|
set format y "%.0s %c"
|
||
|
|
||
|
set title "MRTG from $1"
|
||
|
set ylabel "Bytes per Second"
|
||
|
set xlabel "Time"
|
||
|
|
||
|
plot "$1" using (\$1+$TIMEOFFSET):4 t 'In' lt rgb 'green' w filledcurves y1=0 , \
|
||
|
"$1" using (\$1+$TIMEOFFSET):5 t 'Out' lt rgb 'blue' w lines
|
||
|
|
||
|
|
||
|
EOF
|
||
|
) >$TEMPFILE
|
||
|
|
||
|
gnuplot $TEMPFILE
|
||
|
rm -f $TEMPFILE
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| gnuplot.cgi | ||
|---|---|---|
|
#!/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
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
Also available in: Unified diff
Add two systems for plotting MRTG log data in gnuplot