Google Answers Logo
View Question
 
Q: Is there a way to get an e-mail when Linux iowait rises past a certain level? ( No Answer,   9 Comments )
Question  
Subject: Is there a way to get an e-mail when Linux iowait rises past a certain level?
Category: Computers > Operating Systems
Asked by: davert3-ga
List Price: $12.00
Posted: 23 Nov 2005 12:37 PST
Expires: 09 Dec 2005 11:10 PST
Question ID: 596839
I'd like to know if there's a way to monitor Linux iowait percentages
so that when it rises past a certain level for an amount of time, a
warning is automatically sent.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Is there a way to get an e-mail when Linux iowait rises past a certain level
From: feldersoft-ga on 23 Nov 2005 20:55 PST
 
You can tell iostat to print cpu data constantly over a certain
interval.  For example:

iostat -c 1

will print cpu info once every second.

Writing a shell/perl script to run the above command, monitor the
output, and send an email when your threshold is met shouldn't be all
that difficult.
Subject: Re: Is there a way to get an e-mail when Linux iowait rises past a certain level?
From: davert3-ga on 24 Nov 2005 06:54 PST
 
It shouldn't be, but for me, it is. If you do it I'll happily raise
the question $ and give you the final answer. Though I think I'd
rather have it monitoring every ten seconds...
Subject: Re: Is there a way to get an e-mail when Linux iowait rises past a certain level
From: feldersoft-ga on 24 Nov 2005 16:59 PST
 
iostat -c 10 would do every 10 seconds...I'm not a ga researcher so I
can't post it as an answer...maybe one will read my comment and write
the script for you.
Subject: Re: Is there a way to get an e-mail when Linux iowait rises past a certain level
From: feldersoft-ga on 24 Nov 2005 17:43 PST
 
If someone doesn't write the script for you, I'll do it via payment
from paypal or something.  I'd want around $100 for doing it though
because it would take an hour or two of my time to do it, plus you'd
probably want some support getting it going.

I'd require half up front and the other half when the script is
finished.  Post a comment here if you're interested.
Subject: Re: Is there a way to get an e-mail when Linux iowait rises past a certain level?
From: davert3-ga on 28 Nov 2005 12:31 PST
 
Make it $70 and you've got a deal
Subject: Re: Is there a way to get an e-mail when Linux iowait rises past a certain level?
From: rssohan-ga on 08 Dec 2005 17:05 PST
 
Note: Created with,sysstat version 5.0.6
bash version 2.05b.0(1)-release

You may need to massage it a little for other versions of sysstat,bash.
your mileage may vary, yadda yadda...
mail me if you need help.

-----------------------------------------------------------------------------
#!/bin/bash

IOSTAT_CMD="/usr/bin/iostat"

#this is the colum number for the iowait value
IOSTAT_VAL_NO=13

#the frequency at which to wake up and check the iowait value in secs
CHECK_FREQ=10 

#the threshold which is considered dangerous (in whole numbers)
IOWAIT_THRESHOLD=40

#the period above which the iowait value must contin.stay for email to be sent
#in seconds
MAX_OVERLOAD_PER=5

#the person(s) to send mail to
MAIL_ADDR="rss"



function send_warning_mail()
{
    HOSTNAME="`hostname -f`"
    DATE_STRING="`date '+%d/%y/%m [%H:%M]'`"
    mail -s "${HOSTNAME} [${DATE_STRING} ] -- iowait load avg exceeded" <<EOF \
	${MAIL_ADDR}
    Automated Message from ${HOSTNAME} on ${DATE_STRING}
    The IOWAIT theshold exceeded $1 (last value $2) for $3 seconds.  
    Please fix, k, thx.
    
EOF
}


function get_iowait_val()
{

TMP=`$IOSTAT_CMD`

i=0
for val in $TMP
do
  [ $i == $IOSTAT_VAL_NO ] && break
i=$((i+1))
done

##empty val value
[ $val == "" ] && {
    echo "error getting iostat val, check the column number is corr"
    exit 1
}

##check we're a number
###start by checking we have a "."
period_index=`expr index $val '.'`
[ $period_index -eq 0 ] && {
    echo "error parsing period from iostat val, check column is corr"
    exit 1
}

##get up until the period
val=`expr substr $val 1 $((period_index-1))`
iowait_val=$((val))

}

ovrld_st=0

while :

do
  get_iowait_val
  
 if [ $iowait_val -gt $IOWAIT_THRESHOLD ] ; then
     date=`date +'%s'`

     #update the over_threshold_period value
     #if it's 0, set it to the current date (start mark) else
     #just calc the delta
     if [ $ovrld_st -eq 0 ]; then
	 
	 ovrld_st=$((date))
     else	

	[ $((date-ovrld_st)) -gt $MAX_OVERLOAD_PER ] && {
	    send_warning_mail $IOWAIT_THRESHOLD $iowait_val $MAX_OVERLOAD_PER
	    ovrld_st=0
	}
     fi

 else
     ovrld_st=0
fi
     
sleep $CHECK_FREQ
done
Subject: Re: Is there a way to get an e-mail when Linux iowait rises past a certain level?
From: davert3-ga on 09 Dec 2005 06:08 PST
 
You need to post that as an answer so I can pay you! Thanks!!!
Subject: Re: Is there a way to get an e-mail when Linux iowait rises past a certain level?
From: rssohan-ga on 09 Dec 2005 10:56 PST
 
consider it a free gift :)
Subject: Re: Is there a way to get an e-mail when Linux iowait rises past a certain level?
From: davert3-ga on 09 Dec 2005 11:10 PST
 
Thank you!!!

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy