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
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
21 # source the PCP configuration environment variables
22 .
$PCP_DIR/etc
/pcp.env
25 tmp
=`mktemp -d /tmp/pcp.XXXXXXXXX` ||
exit 1
26 trap "rm -fr $tmp; exit \$status" 0 1 2 3 15
32 # usage - print out the usage of program
36 echo >$tmp/msg
"Usage: $prog [options] [pmgadgets options] [host ...]"
39 Default hosts are specified in /etc/nodes (or /etc/ace/nodes).
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
59 echo -n " \"$arg\"" >>$tmp/conf
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" ]
74 [ ! -f "$nodesfile" ] && nodesfile
=/etc
/ace
/nodes
76 nodesfile
="$PCP_CLUSTER_CONFIG"
77 if [ ! -f "$nodesfile" ]
79 echo "Error: \"$nodesfile\" specified in \$PCP_CLUSTER_CONFIG: file not found"
97 *) pmgargs
="$pmgargs $1"
106 if [ -n "$otherArgs" ]
108 while getopts "H:r:lV?" c
$otherArgs
113 if [ ! -f "$nodesfile" ]
115 echo "$prog Error: \"$nodesfile\" for -H file not found"
123 l
) pmgsysargs
="$pmgsysargs -l"
135 shift `expr $OPTIND - 1`
140 if [ "$interval" != "0" ]
142 args
="$args -t $interval"
145 if [ ! -z "$titleArg" ]
147 args
="$args -title $titleArg"
151 if [ ! -z "$titlelabel" ]
154 echo "_label 6 13 \"$titlelabel\" \"7x13bold\"" >> $tmp/conf
157 if [ "$nhosts" -eq 0 ]
162 if [ -f "$nodesfile" ]
164 hosts
=`sed -e 's/[# ].*$//' $nodesfile`
165 nhosts
=`echo $hosts | wc -w`
192 rows
=`echo "sqrt($nhosts)" | bc`
195 cols
=`expr $nhosts / $rows`
199 if ! pmgsys
$pmgsysargs -C -V -h $host > $tmp/pmgsys
2> $tmp/pmgsys.err
201 sed -e "s/pmgsys/$prog/g" $tmp/pmgsys.err
>&2
205 sed -e 's/^pmgadgets/# pmgadgets/' \
206 -e "/.*_update.*/d" \
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" \
222 /^_/ && $2 ~ /^[0-9]+$/ && $3 ~ /^[0-9]+$/ {
223 printf "%s %d %d ", $1, $2 + '$ox', $3 + '$oy'
224 for (i=4; i <= NF; i++)
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]+$/ {
244 printf "host_xmax=%d; ymax=%d", xmax, ymax
247 [ $host_xmax -gt $xmax ] && xmax
=$host_xmax
250 if [ $row -eq $rows ]
254 ox
=`expr $xmax + $xgap`
257 oy
=`expr $ymax + $ygap`
261 hostnum
=`expr $hostnum + 1`
264 rm -f $tmp/pmgsys
$tmp/pmgsys.err
271 if [ $hostnum -le 0 ]
273 echo "$prog: unable to monitor any hosts" >&2
278 eval pmgadgets
$args <$tmp/conf