Pejman Moghadam / Scripts

MRTG Hard Disk iostat.txt

Public domain


Incomplete

#!/bin/bash

# Variables
PATH="$PATH:/usr/local/mrtg-2/bin"
CFG="/usr/local/mrtg-2/etc/mrtg-iostat.cfg"
WRKDIR="/var/www/htdocs/iostat"
HOST=$(hostname)
UPTIME=$(cat /proc/uptime | sed -e 's,\..*,,')
H=$(( $UPTIME / 3600 ))
M=$(( ($UPTIME - $H * 3600) / 60  ))
TMP=/tmp/stat.$$

# This function appends configuration for a device
# or a partition to config file
append_to_config_file() {
cat >> $CFG << EOF

################################################################################
##### ${DEV} ###################################################################
##### Device:         rrqm/s   wrqm/s   r/s   w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
##### ${LINE}
################################################################################



Target[${DEV}_KBS]: \`printf "%s\n%s\n%s\n%s\n" ${RKBS} ${WKBS} ${H}:${M} ${HOST}\`
Options[${DEV}_KBS]: gauge, nopercent, integer, unknaszero
Title[${DEV}_KBS]: [${DEV}] Kilobits read/write per second
PageTop[${DEV}_KBS]: <H1>[${DEV}] Kilobits read/write per second</H1>
YLegend[${DEV}_KBS]: Kbits per second
ShortLegend[${DEV}_KBS]: kbps
Colours[${DEV}_KBS]: YELLOW#F9C000,RED#F90000,DARKGREEN#006600,VIOLET#FF00FF
Legend1[${DEV}_KBS]: Kilobits read per second
Legend2[${DEV}_KBS]: Kilobits write per second
LegendI[${DEV}_KBS]: Read
LegendO[${DEV}_KBS]: Write
MaxBytes[${DEV}_KBS]: 100000

Target[${DEV}_TIME]: \`printf "%s\n%s\n%s\n%s\n" ${AWAIT} ${SVCTM} ${H}:${M} ${HOST}\`
Options[${DEV}_TIME]: gauge, nopercent, integer, unknaszero
Title[${DEV}_TIME]: [${DEV}] Await / Service time
PageTop[${DEV}_TIME]: <H1>[${DEV}] Await / Service time</H1>
YLegend[${DEV}_TIME]: milliseconds
ShortLegend[${DEV}_TIME]: ms
Colours[${DEV}_TIME]: YELLOW#F9C000,RED#F90000,DARKGREEN#006600,VIOLET#FF00FF
Legend1[${DEV}_TIME]: Await for issued requests
Legend2[${DEV}_TIME]: service time for issued requests
LegendI[${DEV}_TIME]: await
LegendO[${DEV}_TIME]: svctm
MaxBytes[${DEV}_TIME]: 100000

Target[${DEV}_RRQMS]: \`printf "%s\n%s\n%s\n%s\n" ${RS} ${RRQMS} ${H}:${M} ${HOST}\`
Options[${DEV}_RRQMS]: gauge, nopercent, integer, unknaszero
Title[${DEV}_RRQMS]: [${DEV}] Read requests issued/queued per second
PageTop[${DEV}_RRQMS]: <H1>[${DEV}] Read requests issued/queued per second</H1>
YLegend[${DEV}_RRQMS]: req / sec
ShortLegend[${DEV}_RRQMS]: req
Colours[${DEV}_RRQMS]: YELLOW#F9C000,RED#F90000,DARKGREEN#006600,VIOLET#FF00FF
Legend1[${DEV}_RRQMS]: Issued requests per second
Legend2[${DEV}_RRQMS]: Queued requests per second
LegendI[${DEV}_RRQMS]: Issued
LegendO[${DEV}_RRQMS]: Queued
MaxBytes[${DEV}_RRQMS]: 100000

Target[${DEV}_WRQMS]: \`printf "%s\n%s\n%s\n%s\n" ${WS} ${WRQMS} ${H}:${M} ${HOST}\`
Options[${DEV}_WRQMS]: gauge, nopercent, integer, unknaszero
Title[${DEV}_WRQMS]: [${DEV}] Write requests issued/queued per second
PageTop[${DEV}_WRQMS]: <H1>[${DEV}] Write requests issued/queued per second</H1>
YLegend[${DEV}_WRQMS]: req / sec
ShortLegend[${DEV}_WRQMS]: req
Colours[${DEV}_WRQMS]: YELLOW#F9C000,RED#F90000,DARKGREEN#006600,VIOLET#FF00FF
Legend1[${DEV}_WRQMS]: Issued requests per second
Legend2[${DEV}_WRQMS]: Queued requests per second
LegendI[${DEV}_WRQMS]: Issued
LegendO[${DEV}_WRQMS]: Queued
MaxBytes[${DEV}_WRQMS]: 100000


EOF
}


# Main function

iostat -dkx | egrep -v "^ *$|^Device:|$(hostname)"> ${TMP}
mkdir -p "${WRKDIR}"
echo "workdir: ${WRKDIR}" > ${CFG}

for DEV in $(cat ${TMP} | awk '{print$1}'); do
  LINE=$(grep "${DEV} " ${TMP})
  RRQMS=$(echo $LINE | awk '{print$2}')
  WRQMS=$(echo $LINE | awk '{print$3}')
  RS=$(echo $LINE | awk '{print$4}')
  WS=$(echo $LINE | awk '{print$5}')
  RKBS=$(echo "$(echo $LINE | awk '{print$6}') * 8" | bc)
  WKBS=$(echo "$(echo $LINE | awk '{print$7}') * 8" | bc)
  AVGRQSZ=$(echo $LINE | awk '{print$8}')
  AVGQUSZ=$(echo $LINE | awk '{print$9}')
  AWAIT=$(echo $LINE | awk '{print$10}')
  SVCTM=$(echo $LINE | awk '{print$11}')
  UTIL=$(echo $LINE | awk '{print$12}')
  #echo $DEV $RRQMS $WRQMS $RS $WS $RKBS $WKBS $AVGRQSZ $AVGQUSZ $AWAIT $SVCTM $UTIL
  append_to_config_file
done

rm -f ${TMP}
indexmaker ${CFG} > ${WRKDIR}/index.html
mrtg ${CFG}

BY: Pejman Moghadam
TAG: mrtg, bash, bash-script
DATE: 2010-09-22 14:00:51


Pejman Moghadam / Scripts [ TXT ]