-
Notifications
You must be signed in to change notification settings - Fork 0
/
mon_load.sh
executable file
·44 lines (38 loc) · 1.26 KB
/
mon_load.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
set -f
CLIENT="$1"
BASEDIR=$(dirname $0)
CONFIG="mon.ini"
if [ -n "$CLIENT" ]; then
shift
CONFIG=${CONFIG}.${CLIENT}
if [ ! -s "$BASEDIR/$CONFIG" ]; then echo "Exiting... Config not found: "$CONFIG ; exit 128; fi
fi
echo "Using config: ${CONFIG}"
LOGDIR="$BASEDIR/../log"
if [ ! -d "$LOGDIR" ]; then mkdir -p "$LOGDIR"; fi
HOSTS=$($BASEDIR/iniget.sh $CONFIG servers host)
limPER=$($BASEDIR/iniget.sh $CONFIG load limitPER)
for HOST in $(xargs -n1 echo <<< "$HOSTS"); do
LOGF=$LOGDIR/mon_swap_${HOST}.log
LOGF_HEAD=$LOGDIR/mon_swap_${HOST}_head.log
echo "HOST: "$HOST
$BASEDIR/test_ssh.sh $CLIENT $HOST
if [ "$?" -ne 0 ]; then echo "test_ssh.sh not return 0, continue"; continue; fi
OS=$(ssh $HOST "uname")
case "$OS" in
Linux)
ssh "$HOST" "cat /proc/loadavg | awk '{printf (\"%3.0f\", \$2)}'" > $LOGF
PCT=$(head -1 $LOGF)
;;
AIX) ssh "$HOST" "lparstat 6 1 | tail -1 | awk '{printf (\"%3.0f\", \$7)}'" > $LOGF
PCT=$(head -1 $LOGF)
;;
esac
if [ "$PCT" -ge "$limPER" ]; then
echo -e "Fired: "$0"\n" > $LOGF_HEAD
cat $LOGF_HEAD $LOGF | $BASEDIR/send_msg.sh $CONFIG $HOST NULL "Overall OS Load warning: (current: ${PCT} %, threshold: ${limPER} %)"
rm $LOGF_HEAD
fi
rm $LOGF
done