#!/bin/bash
########################################################
# Author: Brian T. Hunter
# Date: 9/1/2023
# Script: bb-iostat.sh
########################################################
# 1. YOU Need to install iostat on Linux by:
# sudo apt install sysstat
#
# 2. ADD to the bottom of file /etc/xymon/tasks.cfg
#
# [iostat]
# ENVFILE $XYMONCLIENTHOME/etc/xymonclient.cfg
# CMD $XMONCLIENTHOME/ext/bb-iostat.sh
# LOGFILE $XYMONCLIENTLOGS/bb-iostat.log
# INTERVAL 5m
#
# 3. I ADDED to TEST2RRD variable in /etc/xymon/xymonservers.cfg
# iostat=ncv
#
# 4. I ADDED to GRAPHS variable in /etc/xymon/xymonservers.cfg
# iostat::100
#
# 5. I ADDED to BOTTOM in /etc/xymon/xymonservers.cfg
# SPLINTNCV_iostat="*:GUAGE"
#
# 6. ADD [iostat] to /etc/xymon/graphs.cfg and COMMENT EXISTING [iostat] OUT !
#
# [iostat]
# FNPATTERN ^iostat,(.*).rrd
# TITLE I/O Utilization
# YAXIS Stats
# DEF:***@RRDIDX@=@RRDFN@:lambda:AVERAGE
# LINE2:***@RRDIDX@#@COLOR@:@RRDPARAM@
# GPRINT:***@RRDIDX@:LAST: \: %8.1lf (cur)
# GPRINT:***@RRDIDX@:MAX: \: %8.1lf (max)
# GPRINT:***@RRDIDX@:MIN: \: %8.1lf (min)
# GPRINT:***@RRDIDX@:AVERAGE: \: %8.1lf (avg)\n
# 7. THEN RESTART XYMON: sudo systemctl restart xymon
#
# NOTES:
# iostat -N 300 2
########################################################
COLUMN=iostat
COLOR=green
MACHINE=`hostname`
MSG="IOSTAT DISK PERFORMANCE CHECK"
LOGFILE=/tmp/$MACHINE.$COLUMN.out
OUTPUT=/tmp/$MACHINE.$COLUMN.output
MOUNT="/bin/mount"
AWK="/usr/bin/awk"
GREP="/bin/grep"
SORT="/usr/bin/sort"
SED="/bin/sed"
RM="/bin/rm"
/usr/bin/iostat -N 10 2 | tail -10 > $LOGFILE
# /usr/bin/iostat -N 10 1 > $LOGFILE
for device in `$MOUNT | $AWK '{print $1}' | $GREP "\/dev" | $SORT -u | $AWK -F/ '{print $3}'`
do
DEVICE=`$GREP $device $LOGFILE | $SED 's/ */:/g'`
MYDEV=`echo $DEVICE | $AWK -F: '{print $1}'`
TPS=`echo $DEVICE | $AWK -F: '{print $2}'`
READPERSEC=`echo $DEVICE | $AWK -F: '{print $3}'`
WRITEPERSEC=`echo $DEVICE | $AWK -F: '{print $4}'`
DSCDPERSEC=`echo $DEVICE | $AWK -F: '{print $5}'`
READ=`echo $DEVICE | $AWK -F: '{print $6}'`
WRITE=`echo $DEVICE | $AWK -F: '{print $7}'`
DSCD=`echo $DEVICE | $AWK -F: '{print $8}'`
printf "
${MYDEV}_TPS:$TPS
${MYDEV}_READPERSEC:$READPERSEC
${MYDEV}_WRITEPERSEC:$WRITEPERSEC
${MYDEV}_DSCDPERSEC:$DSCDPERSEC
${MYDEV}_READ:$READ
${MYDEV}_WRITE:$WRITE
${MYDEV}_DSCD:$DSCD
" >> $OUTPUT
done
MESSAGE="IOSTAT DISK PERFORMANCE CHECK"
MSG="${MESSAGE}
`cat $OUTPUT`
"
$XYMON $XYMSRV "status $MACHINE.$COLUMN $COLOR `date`
${MSG}
"
$RM $OUTPUT
exit 0