docs: describe the pmdaroot process interfaces
[pcp.git] / src / pmgadgets / pmgcluster.sh
blobddd2229702a040d1defbae07ce6813b2b6de7c23
1 #!/bin/sh
3 # Copyright (c) 2014 Red Hat.
4 # Copyright (c) 1995-2002 Silicon Graphics, Inc. All Rights Reserved.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; either version 2 of the License, or (at your
9 # option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 # for more details.
17 # This script uses pmgsys to layout gadgets for a series of hosts and then
18 # combines the resulting config files into one big one and invokes pmgadgets
19 # on the result.
21 # source the PCP configuration environment variables
22 . $PCP_DIR/etc/pcp.env
24 status=1
25 tmp=`mktemp -d /tmp/pcp.XXXXXXXXX` || exit 1
26 trap "rm -fr $tmp; exit \$status" 0 1 2 3 15
27 verbose="false"
28 prog=`basename $0`
29 nhosts=0
30 hosts=""
32 # usage - print out the usage of program
34 _usage()
36 echo >$tmp/msg "Usage: $prog [options] [pmgadgets options] [host ...]"
37 echo >>$tmp/msg '
39 Default hosts are specified in /etc/nodes (or /etc/ace/nodes).
41 options:
42 -H nodes file specifying nodes in cluster
43 [default $PCP_CLUSTER_CONFIG or /etc/nodes]
44 -r rows number of rows for layout
45 -l suppress host name labels
46 -L label title label for pmgagdets layout
47 -V verbose (print pmgadgets configuration)
49 pmgadgets(1) options:'
50 _pmgadgets_usage | sed -e '/.*-h host.*/d' >>$tmp/msg
51 _pmgadgets_info -f $tmp/msg
54 # keep the original command line for restart after logout/login
56 echo -n "pmgadgets 1 \"pmgcluster\"" >$tmp/conf
57 for arg
59 echo -n " \"$arg\"" >>$tmp/conf
60 done
61 echo >>$tmp/conf
63 # get arguments
65 . $PCP_SHARE_DIR/lib/pmgadgets-args
68 # Have to pre-parse the options for -L coz getopts can't handle multiword
69 # strings when using $otherArgs
71 if [ -z "$PCP_CLUSTER_CONFIG" ]
72 then
73 nodesfile=/etc/nodes
74 [ ! -f "$nodesfile" ] && nodesfile=/etc/ace/nodes
75 else
76 nodesfile="$PCP_CLUSTER_CONFIG"
77 if [ ! -f "$nodesfile" ]
78 then
79 echo "Error: \"$nodesfile\" specified in \$PCP_CLUSTER_CONFIG: file not found"
80 _usage
81 status=1
82 exit
86 while [ $# -gt 0 ]
88 case $1
90 -h) hosts="$2"
91 nhosts=1
92 shift
94 -L) titlelabel="$2"
95 shift
97 *) pmgargs="$pmgargs $1"
99 esac
100 shift
101 done
102 set -- $pmgargs
104 _pmgadgets_args "$@"
106 if [ -n "$otherArgs" ]
107 then
108 while getopts "H:r:lV?" c $otherArgs
110 case $c
112 H) nodesfile=$OPTARG
113 if [ ! -f "$nodesfile" ]
114 then
115 echo "$prog Error: \"$nodesfile\" for -H file not found"
116 _usage
117 status=1
118 exit
121 r) rows=$OPTARG
123 l) pmgsysargs="$pmgsysargs -l"
125 V) verbose="true"
127 ?) _usage
128 status=1
129 exit
131 esac
132 done
134 set -- $otherArgs
135 shift `expr $OPTIND - 1`
136 else
137 set --
140 if [ "$interval" != "0" ]
141 then
142 args="$args -t $interval"
145 if [ ! -z "$titleArg" ]
146 then
147 args="$args -title $titleArg"
150 ytitle=0
151 if [ ! -z "$titlelabel" ]
152 then
153 ytitle=16
154 echo "_label 6 13 \"$titlelabel\" \"7x13bold\"" >> $tmp/conf
157 if [ "$nhosts" -eq 0 ]
158 then
159 nhosts=$#
160 if [ $nhosts -eq 0 ]
161 then
162 if [ -f "$nodesfile" ]
163 then
164 hosts=`sed -e 's/[# ].*$//' $nodesfile`
165 nhosts=`echo $hosts | wc -w`
167 else
168 hosts=$*
172 if [ $nhosts -eq 0 ]
173 then
174 _usage
175 status=1
176 exit
180 ox=0
181 oy=$ytitle
182 row=0
183 col=0
184 ygap=20
185 xgap=50
186 xmax=0
187 ymax=0
188 hostnum=0
190 if [ -z "$rows" ]
191 then
192 rows=`echo "sqrt($nhosts)" | bc`
195 cols=`expr $nhosts / $rows`
197 for host in $hosts
199 if ! pmgsys $pmgsysargs -C -V -h $host > $tmp/pmgsys 2> $tmp/pmgsys.err
200 then
201 sed -e "s/pmgsys/$prog/g" $tmp/pmgsys.err >&2
202 continue
205 sed -e 's/^pmgadgets/# pmgadgets/' \
206 -e "/.*_update.*/d" \
207 -e "s/-C//g" \
208 -e "s/cpuActions/"$hostnum"_cpuActions/g" \
209 -e "s/loadActions/"$hostnum"_loadActions/g" \
210 -e "s/netActions/"$hostnum"_netActions/g" \
211 -e "s/diskActions/"$hostnum"_diskActions/g" \
212 -e "s/diskLegend/"$hostnum"_diskLegend/g" \
213 -e "s/cpuColours/"$hostnum"_cpuColours/g" \
214 -e "s/netColours/"$hostnum"_netColours/g" \
215 -e "s/kernel\./"$host":kernel./g" \
216 -e "s/disk\./"$host":disk./g" \
217 -e "s/mem\./"$host":mem./g" \
218 -e "s/swap\./"$host":swap./g" \
219 -e "s/network\./"$host":network./g" \
220 $tmp/pmgsys \
221 | $PCP_AWK_PROG '
222 /^_/ && $2 ~ /^[0-9]+$/ && $3 ~ /^[0-9]+$/ {
223 printf "%s %d %d ", $1, $2 + '$ox', $3 + '$oy'
224 for (i=4; i <= NF; i++)
225 printf "%s ", $i
226 printf "\n"
227 next
230 print
231 }' | tee $tmp/$host >> $tmp/conf
234 # set xmax and ymax for this host
236 eval `$PCP_AWK_PROG '
237 /^_/ && $2 ~ /^[0-9]+$/ && $3 ~ /^[0-9]+$/ {
238 if (xmax < $2)
239 xmax = $2
240 if (ymax < $3)
241 ymax = $3
243 END {
244 printf "host_xmax=%d; ymax=%d", xmax, ymax
245 }' $tmp/$host`
247 [ $host_xmax -gt $xmax ] && xmax=$host_xmax
249 row=`expr $row + 1`
250 if [ $row -eq $rows ]
251 then
252 row=0
253 oy=$ytitle
254 ox=`expr $xmax + $xgap`
255 col=`expr $col + 1`
256 else
257 oy=`expr $ymax + $ygap`
260 rm -f $tmp/$host
261 hostnum=`expr $hostnum + 1`
262 done
264 rm -f $tmp/pmgsys $tmp/pmgsys.err
266 if $verbose
267 then
268 cat $tmp/conf
271 if [ $hostnum -le 0 ]
272 then
273 echo "$prog: unable to monitor any hosts" >&2
274 status=1
275 exit
278 eval pmgadgets $args <$tmp/conf
280 status=$?
281 exit