-
Notifications
You must be signed in to change notification settings - Fork 0
/
vs-stats
executable file
·86 lines (71 loc) · 1.49 KB
/
vs-stats
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
#!/bin/bash
. /usr/lib/vs-tools/functions.sh
begin
# ---------------------------------------------------------------------------------------------------------
function help {
sed -e "s/^#//g"<<EOF
#
#Usage: $(basename $0) <Args>
#
#Function: show vserver or host statistics
#
#Args: [ --host [<host>] ]
# [ --name <vserver> ]
#
# * Remote statistics are available for master host only.
#
EOF
}
# ---------------------------------------------------------------------------------------------------------
# Read arguments
HOST=_
while [ $# -gt 0 ] ; do
case "$1" in
--help)
help
exit 0
;;
--host)
if [ "$2" ] ; then
if [ "$2" != "--name" ] ; then
HOSTS_LIST=$(get_hosts_list)
if [ ! "$HOSTS_LIST" ] ; then
abort "'$(hostname -s)' is not a master vserver"
fi
shift
HOST=$1
fi
fi
;;
--name)
if [ "$2" ] && [ "$2" != "--host" ] ; then
shift
NAME=$1
fi
;;
esac
shift
done
# ---------------------------------------------------------------------------------------------------------
if [ "$HOST" == "_" ] ; then
if [ "$NAME" ] ; then
vs-functions get_vserver_stats $NAME
else
vs-functions get_host_stats
fi
else
if [ ! "$(test_ping $HOST)" ] ; then
echo "$HOST:UNREACHABLE"
exit 1
fi
if [ ! "$(test_ssh $HOST)" ] ; then
echo "$HOST:DENIED"
exit 1
fi
if [ "$NAME" ] ; then
ssh $HOST "vs-functions get_vserver_stats $NAME" $LABEL
else
ssh $HOST "vs-functions get_host_stats" $LABEL
fi
fi
success