Total Pageviews

Friday, 31 July 2009

Bash script to capture %iowait performance using Sysstat Sar

Posted by Jesus Bustos on 31-Jul-2009 08:59:08

Recently I needed to capture, some information regarding %iowait when, I created a script to make it simpler.

#!/bin/bash
antes=`sar -u 0 | awk '{print $6}'`
iol=`echo $antes | awk '{print $2}'`
c=`echo $iol \* 100 |bc`
b=${c/.*}
a=5
date=`date`
hostname=`hostname`
file=/tmp/iowaitperformance
if [ $b -gt $a ] ; then
clear
echo Enter your email
read email
echo -e "Gathering information \t"
echo -n "[#Sar "
sleep 1
sar 1 -u 30 >> /tmp/iowaitperformance
echo -n "# vmstat"
vmstat -D >> /tmp/iowaitperformance
echo -n "# vmstat"
vmstat -d >> /tmp/iowaitperformance
echo -n "# iostat"
iostat -k >> /tmp/iowaitperformance
echo -n "# pidstat"
pidstat -d 1 10 >> /tmp/iowaitperformance
echo -n "# ps"
ps wwwaux >> /tmp/iowaitperformance
echo -n "#"
echo -n "#"
echo -n "#"
echo -n "#"
echo -n "#sending e-mail $email "
cat /tmp/iowaitperformance | mail -s Performance $email
echo "100%]"
echo -e "The information has been sent to $email also available here $file."
else
echo -e "El %iowait es $iol%. \nRun the script when the %iowait is high. \n$date $hostname "
fi

No comments: