Skip to content

Instantly share code, notes, and snippets.

@theeye-io
Last active May 16, 2017 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theeye-io/ca05cd48a147eba97938edba32040bc5 to your computer and use it in GitHub Desktop.
Save theeye-io/ca05cd48a147eba97938edba32040bc5 to your computer and use it in GitHub Desktop.
Connect via ssh , run iostat command , and parse
#!/bin/bash
#
# Script Parameters.
# ==============
# @param $1 device
# @param $2 limit
# @param $3 column
#
# do man iostat for more data
# columns
# 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11
# r/s | w/s | kr/s | kw/s | wait | actv | wsvc_t | asvc_t | %w | %b | device#
#
# (1, 2, 3) = (r/w , w/s , kw/s)
# 8 = asvc_t
# 10 = %b
# 11 = device
#
device=$1
limit=$2
column=$3
user='theeye'
host='thehost'
echo "checking if $device value in column $column is lower than $limit"
test $device || { echo "no device on \$1"; exit 1; }
test $limit || { echo "no limit on \$2"; exit 2; }
test $column || { echo "no column on \$3"; exit 3; }
echo "getting data from bdcrmqa02"
#
# Command to obtain the data
#iostat -Xcnr 3 2 | tac | sed '/extended device/q' | tac | sed '1,2d' | while read line; do echo "$line"; done
#
data=$(ssh $user@$host 'iostat -Xcnr 3 2 | tac | sed "/extended device/q" | tac | sed "1,2d" | while read line; do echo "$line"; done')
#echo "$data"
alert="no"
while read line; do
echo $line | grep $device
if [[ $? == 0 ]]; then
val=$(echo $line | cut -d',' -f$column)
result=$(echo $val'>'$limit | bc -l)
if [[ $result == 1 ]]; then
alert="yes"
fi
fi
done <<< "$(echo -e "$data")"
if [ $alert == 'yes' ]
then
echo "{\"state\":\"failure\",\"data\":{\"value\":$val}}"
else
echo "{\"state\":\"success\",\"data\":{\"value\":$val}}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment