Last active
May 16, 2017 18:49
-
-
Save theeye-io/ca05cd48a147eba97938edba32040bc5 to your computer and use it in GitHub Desktop.
Connect via ssh , run iostat command , and parse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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