#! /bin/sh
if [ $# -ne 1 ]; then
echo "Usage: $0 "
exit 1
fi
sarfile=$1
if [ ! -f $sarfile ]; then
echo "Error. $sarfile does not exist"
exit 2
fi
tmp=/tmp/.tmp-`basename $0`
# CPU
# user sys wio idle
sar -f $sarfile | awk ' /^[0-9].*[0-9]$/ && length($0)>0 && $NF !~ /[a-z]/ {print $4,$5,6,$7} /Average/ {exit} ' > $tmp-cpu
# NETWORK
# rxbyt/s wxbyt/s
sar -f $sarfile -n FULL | awk ' /^[0-9].*[0-9]$/ && length($0)>0 && $NF !~ /[a-z]/ && /eth0/ {print $6,$7} /Average/ {exit} ' > $tmp-net
# MEMORY
# memused% swpused%
sar -f $sarfile -r | awk ' /^[0-9].*[0-9]$/ && length($0)>0 && $NF !~ /[a-z]/ {print $5,$11} /Average/ {exit} ' > $tmp-mem
# RUN QUEUE
# runq-sz plist-sz ldavg1 ldavg5
sar -f $sarfile -q | awk ' /^[0-9].*[0-9]$/ && length($0)>0 && $NF !~ /[a-z]/ {print $3,$4,$5,$6} /Average/ {exit} ' > $tmp-run
#
# print time (epoch)
sar -f $sarfile -h -r | awk '{print $3}' | uniq > $tmp-time
#
# put them all in one file
paste $tmp-time $tmp-cpu $tmp-mem $tmp-net $tmp-run | sed -e 's/\t/ /g' > $tmp-all
host=`hostname`
ymd=`date +'%Y%m%d'`
logdir=/var/log/sa/SAR-RRD
[ ! -d $logdir ] && mkdir -p $logdir
rrdupdate="$logdir/$ymd.rrdupdate"
exec 1> $rrdupdate
echo "HOST=$host"
echo "DS=usr:GAUGE"
echo "DS=sys:GAUGE"
echo "DS=wio:GAUGE"
echo "DS=idl:GAUGE"
echo "DS=memused:GAUGE"
echo "DS=swpused:GAUGE"
echo "DS=rxbyte:GAUGE"
echo "DS=txbyte:GAUGE"
echo "DS=runq:GAUGE"
echo "DS=plist:GAUGE"
echo "DS=ldavg1:GAUGE"
echo "DS=ldavg5:GAUGE"
echo "GRAPH=$ydm-cpu.png:0:100:CPU Utilisation ($host):Percent:1.0:usr#AREA#ff0000,sys#STACK#00ff00,wio#STACK#0000ff,idl#STACK#ffffff"
echo "GRAPH=$ydm-net.png:0:U:Network Utilisation ($host):Kbps:0.0078125:rxbyte#AREA#00ff00,txbyte#LINE2#0000ff"
echo "GRAPH=$ydm-mem.png:0:100:Memory Utilisation ($host):Percent:1.0:memused#LINE2#00ff00,swpused#LINE2#0000ff"
echo "GRAPH=$ydm-run.png:0:U:Run Queue / Average Load ($host):Queue/AveLoad:1.0:runq#LINE2#00ff00,ldavg5#LINE2#0000ff"
cat $tmp-all
rm -f $tmp-cpu $tmp-net $tmp-mem $tmp-run $tmp-all $tmp-time
0 Comments:
Post a Comment
<< Home