summaryrefslogtreecommitdiff
path: root/src/pmview/front-ends/clustervis
blob: 6cab7aacfa0ac7bd82105ead005b1f235ce0288a (plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/bin/sh
#
# Copyright (c) 2001 Silicon Graphics, Inc.  All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#

tmp=/tmp/$$
trap "rm -f $tmp.*; exit" 0 1 2 3  15
rm -f $tmp.*
debug=false

. $PCP_DIR/etc/pcp.env
. $PCP_SHARE_DIR/lib/pmview-args

# --- scaling parameters ---
#

# maximum packets per second
max=750

# maximum req rate (default: 5% of packet rate)
maxreq=`expr $max / 20`

# milliseconds per CPU
maxcpu=1000

#
# clustervis tolerates multiple hosts or archives
_pmview_multiple_sources_are_ok

# --- define usage message ---
#
_usage()
{
    echo >$tmp.msg 'Usage: '$prog' [options]

Default hosts are specified in /etc/nodes (or /etc/ace/nodes)
or specify the file specifying cluster hosts with the -H flag.
The -h flag may be used to specify multiple hosts or the -a flag
may be used to specify multiple archives. The -h, -a and -H flags
are all mutually exclusive.

options:
  -H nodes      file specifying hosts in cluster 
                [default $PCP_CLUSTER_CONFIG or /etc/nodes or /etc/ace/nodes]
  -m max        maximum expected packets sent or received per sec [default 750]
  -V            verbose/diagnostic output  

pmview(1) options:'

    _pmview_usage >> $tmp.msg
    echo >> $tmp.msg
    echo >> $tmp.msg 'Default title is: Web Server Activity'
    echo >> $tmp.msg '
  By default all network interfaces are shown, with a maximum packet rate
  of '$max' packets per second.  The maximum request rate is 5% (of the
  maximum packet rate) and the maximum error rate is 20% of the maximum
  request rate.

  If given, the [interface ...] regular expressions restrict
  the network statistics displayed to matching network interface names only.'

    _pmview_info -f $tmp.msg
}

# --- build WM_COMMAND X(1) property for restart after login/logout ---
#
echo -n "pmview Version 2.1 \"$prog\"" > $tmp.pmview
for arg
do
    echo -n " \"$arg\"" >>$tmp.pmview
done
echo >> $tmp.pmview

# --- parse command line arguments ---
#
verbose=false
argInterfaces=""
hosts=""
interfaces=""
numsource=1
if [ -z "$PCP_CLUSTER_CONFIG" ]
then
    nodesfile=/etc/nodes
    [ ! -f "$nodesfile" ] && nodesfile=/etc/ace/nodes
else
    nodesfile="$PCP_CLUSTER_CONFIG"
    if [ ! -f "$nodesfile" ]
    then
    	echo "Error: \"$nodesfile\" specified in \$PCP_CLUSTER_CONFIG: file not found" 
	_usage
	exit 1
    fi
fi

livemode=false
for f in $*
do
    [ $f = "-h" ] && livemode=true
done

_pmview_args "$@"
$debug && echo "DEBUG msource=\"$msource\""

if [ -n "$otherArgs" ]
then
    while getopts "?H:m:v:V" c $otherArgs
    do
	case $c
	in
	    H)
		nodesfile=$OPTARG
		if [ ! -f "$nodesfile" ]
		then
		    _pmview_error "$prog: \"$nodesfile\" for -H file not found"
		    #NOTREACHED
		fi
		;;
	    m)
		max=$OPTARG
		if [ "X-$max" != "X`expr 0 + -$max 2>/dev/null`" ]
		then
		    _pmview_error "$prog: -m must have a positive integral argument"
		    #NOTREACHED
		fi
		maxreq=`expr $max / 20`
		;;

	    V)
		verbose=true
		;;

	    '?')
		_usage
		exit 1
		;;
	esac
    done
fi

if [ $numsource -eq 0 ]
then
    if [ -f $nodesfile ]
    then
	livemode=true
	sourcelist=`sed -e '/^#/d' $nodesfile`
	numsource=`echo $sourcelist | wc -w`
    else
	_pmview_error "$prog: -H, -a or -h must be given"
    fi
fi

$debug && echo DEBUG sourcelist=\"$sourcelist\"
hostcols=`echo "sqrt($numsource)" | bc`
$debug && echo hostcols=$hostcols


# --- set the window title ---
#
if [ -z "$titleArg" ]
then
    titleArg="SGI PCP : Cluster Node Activity"
fi


# ---- the real config starts here ---
# pmview Version 2.1
#
cat << end-of-file >> $tmp.pmview

_stackLength 26
_marginWidth 4
_marginDepth 4

_colorList net_colors (
        rgbi:0.8/0.0/0.0
	rgbi:0.0/0.8/0.8 
        rgbi:1.0/0.5/0.0
)

_colorList cpu_colors  ( red2 blue2 blue2 )

# main grid
_grid _show (

end-of-file

hostrow=0
hostcol=0
for source in $sourcelist
do
    if $livemode
    then
        host=$source
	msource="-h $source"
    else
    	host=`pmdumplog -l $source | $PCP_AWK_PROG '/^Performance/ {print $NF}'`
	msource="-a $source"
    fi

    nice=`pmprobe $msource -i kernel.all.cpu.nice | $PCP_AWK_PROG '{print $2; exit}'`
    if [ "$nice" = 1 ]
    then
    	nicemetric=kernel.percpu.cpu.nice
    else
    	nicemetric=""
    fi

    _pmview_cache_fetch -v \
	kernel.percpu.cpu.user $nicemetric \
	network.interface.in.packets \
	network.interface.out.packets

    # --- how many CPUs on this system? ---
    #
    if _pmview_fetch -I kernel.percpu.cpu.user
    then
	ncpu=`wc -l <$tmp.pmview_result`
    else
	_pmview_fetch_fail "get the number of CPUs"
    fi

    _pmview_cache_fetch -I network.interface.total.bytes

    # --- how many network interfaces on this system? ---
    #
    if _pmview_fetch -I network.interface.in.packets
    then
	nnet=`grep -v '^lo' $tmp.pmview_result | wc -l`
    else
	_pmview_fetch_fail "get the number of network interfaces"
    fi

    rows=`echo "sqrt($ncpu + $ncpu + $nnet + $nnet)" | bc`
    [ $rows -lt 4 ] && rows=4
    row=0
    col=0

    echo "# grid for host $host" >>$tmp.pmview
    echo "_baseHeight 8" >>$tmp.pmview
    echo "_grid $hostcol $hostrow _hide (" >>$tmp.pmview

    echo "    _baseColor rgbi:0.4/0.4/0.6" >>$tmp.pmview
    echo "    _label 0 0 _down _large \"$host\"" >>$tmp.pmview
    echo "    _grid 1 0 _show (" >>$tmp.pmview

    _pmview_fetch -I kernel.percpu.cpu.user
    for cpu in `cat $tmp.pmview_result`
    do
	echo "      _label $row $col _west \"$cpu\"" >>$tmp.pmview
	echo "	    _stack `expr $row + 1` $col _hide (" >>$tmp.pmview
	echo "	        _metrics (" >>$tmp.pmview
	echo "	            $host:kernel.percpu.cpu.sys[$cpu] $maxcpu" >>$tmp.pmview
	if [ ! -z "$nicemetric" ]
	then
	    echo "		    $host:kernel.percpu.cpu.nice[$cpu] $maxcpu" >>$tmp.pmview
	fi
	echo "		    $host:kernel.percpu.cpu.user[$cpu] $maxcpu" >>$tmp.pmview
	echo "	        )" >>$tmp.pmview
	echo "	            _colorlist cpu_colors" >>$tmp.pmview
	echo "	    )" >>$tmp.pmview

	$debug && echo stack at row=`expr $row + 1` col=$col \"$cpu\"
	$debug && echo label at row=$row col=$col

	col=`expr $col + 1`
	if [ $col -ge $rows ]
	then
	    col=0
	    row=`expr $row + 2`
	fi
    done

    _pmview_fetch -I network.interface.in.packets
    grep -v '^lo' $tmp.pmview_result >$tmp.net
    for net in `cat $tmp.net`
    do
	echo "      _label $row $col _west \"$net\"" >>$tmp.pmview
	echo "      _stack `expr $row + 1` $col _hide (" >>$tmp.pmview
	echo "	        _metrics (" >>$tmp.pmview
	echo "	            $host:network.interface.total.errors[$net] $max" >>$tmp.pmview
	echo "	            $host:network.interface.in.packets[$net] $max" >>$tmp.pmview
	echo "	            $host:network.interface.out.packets[$net] $max" >>$tmp.pmview
	echo "	        )" >>$tmp.pmview
	echo "	        _colorlist net_colors" >>$tmp.pmview
	echo "      )" >>$tmp.pmview

	$debug && echo stack at row=`expr $row + 1` col=$col \"$net\"
	$debug && echo label at row=$row col=$col

	col=`expr $col + 1`
	if [ $col -ge $rows ]
	then
	    col=0
	    row=`expr $row + 2`
	fi

    done
    echo "    )" >>$tmp.pmview
    row=`expr $row + 1`
    echo "# end of host grid" >>$tmp.pmview
    echo ")" >>$tmp.pmview

    hostcol=`expr $hostcol + 1`
    if [ $hostcol -ge $hostcols ]
    then
    	hostcol=0
	hostrow=`expr $hostrow + 1`
    fi

done

echo "" >>$tmp.pmview
echo "# end of main grid" >>$tmp.pmview
echo ")" >>$tmp.pmview

$verbose && cat $tmp.pmview

eval $PMVIEW <$tmp.pmview $args -title "'$titleArg'" -xrm "'*iconName: $prog'"

exit