#!/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





