-
Notifications
You must be signed in to change notification settings - Fork 0
/
masterStats.sh
executable file
·89 lines (78 loc) · 2.37 KB
/
masterStats.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
usage() { echo "Usage: $0 [-w <worker file path>]" 1>&2; exit 1; }
while getopts ":w:" o; do
case "${o}" in
w)
w=${OPTARG}
;;
# d)
# db=${OPTARG}
# ;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${w}" ]; then
usage
fi
echo 1
rm monitor.html 2> /dev/null
touch monitor.html
echo "<html><head><meta http-equiv=\"refresh\" content=\"3\"></head><body><h1>The monitoring service is starting up!</h1></body></html>"> monitor.html
rm tmpmonitor.html 2> /dev/null
mkdir statslogs 2> /dev/null
echo 1.5
while read p; do
if [ "127.0.0.1" != "$p" ] || [ "localhost" != "$p" ] ; then
scp ./stats.sh `echo $p`:/tmp/
fi
done <`echo $w`
#echo 2
while read p; do
touch statslogs/$p.stat
echo "cpu(avg) mem(%) disk(%)" >statslogs/$p.stat
done <`echo $w`
echo 3
while [ 1 ]
do
rm tmpmonitor.html 2> /dev/null
touch tmpmonitor.html
echo "<!DOCTYPE html><html><head><meta http-equiv=\"refresh\" content=\"3\"></ head><body><table style=\"min-width:800px;\"><tr><th>Node</th><th align=\"left\">Cpu (% avg of cores)</th><th align=\"left\">Memory (%)</th><th align=\"left\">Disk (%)</th><th>Message</th></tr>" > tmpmonitor.html
echo 4
while read p; do
#echo $p
if [ "127.0.0.1" == "$p" ] || [ "localhost" == "$p" ] ; then
res=`./stats.sh`
else
res=`rsh -n $p /tmp/stats.sh `
fi
rec=`echo $res | awk -F "|" 'NR==1{print $1}'`
errmsg=`echo $res | awk -F "^" 'NR==1{print $2}'`
echo $rec >> statslogs/$p.stat # write to detailed monitor files
cpu=`echo $rec | awk '{print $1}'` #live monitoring
disk=`echo $rec | awk '{print $3}'`
mem=`echo $rec | awk '{print $2}' | cut -f1 -d"." | cut -f1 -d","`
echo "<tr> <td align=\"center\">${p}</td> <td><meter min=\"0\" max=\"100\" value=\"${cpu}\"></meter> ${cpu}</td> <td><meter min=\"0\" max=\"100\" value=\"${mem}\"></meter> ${mem}</td> <td><meter min=\"0\" max=\"100\" value=\"${disk}\"></meter> ${disk}</td> <td>${errmsg}</td></tr> " >> tmpmonitor.html
#echo 5
done <`echo $w`
echo "</table></body></html>" >> tmpmonitor.html
#echo 6
touch block
#sync
until [ ! -f "./nlock" ]
do
rm block
#echo "nlock exists"
sleep 0.2
touch block
done
#echo "nlock not"
rm monitor.html 2> /dev/null
mv tmpmonitor.html monitor.html
rm block
#echo 7
sleep 4;
#echo 8
done