summaryrefslogtreecommitdiff
path: root/src/pmview/front-ends/osvis
blob: a704446174e70b6ebca1c5a46f4171e56667f4cf (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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
#! /bin/sh
# Copyright (c) 1995-2003 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.*

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

#
# scaling parameters
#

# maximum network packets per second
maxpack=750

# maximum error packets per second
maxerr=`expr $maxpack / 100`

# maximum network bytes per second
maxbyte=65536

# maximum disk io rate (I/O operations per second)
maxio=100

# milliseconds per CPU
maxcpu=1000

# maximum disk activity
maxdisk=30

_usage()
{
    echo >$tmp.msg 'Usage: '$prog' [options] [interface [interface ...]]

options:
  -b bytes      maximum expected network throughput [default 65536 bytes]
  -d activity   maximum expected disk activity as a percentage [default 30]
  -i ops        maximum expected I/O operations per seconds [default 100]
  -m packets    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 'Default title is: High-Level Activity for Host' >> $tmp.msg

    echo >>$tmp.msg '
  By default all network interfaces are shown, with a maximum packet rate
  of '$maxpack' packets per second and error rate of '$maxerr' packets per second.

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

  _pmview_info -f $tmp.msg
}

argInterfaces=""
verbose=false
interfaces=""

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

_pmview_args "$@"

if [ -n "$otherArgs" ]
then
    while getopts "?b:d:i:m:r:v:V" c $otherArgs
    do
	case $c
	in

	    b)
		_pmview_unsigned $c
		maxbyte=$OPTARG
		;;

	    d)
		_pmview_unsigned $c
		maxdisk=$OPTARG
		;;

	    i)
		_pmview_unsigned $c
		maxio=$OPTARG
		;;

	    m)
		_pmview_unsigned $c
		maxpack=$OPTARG
		;;

	    V)
		verbose=true
		;;

	    '?')
		_usage
		exit 1
		;;
	esac
    done

    set -- $otherArgs
    shift `expr $OPTIND - 1`
    if [ $# -gt 0 ]
    then
        argInterfaces="$*"
    fi
fi

cat << end-of-file >> $tmp.conf

#
# osvis
#
end-of-file

# maximum req error rate (default: 1% of packet rate)
maxerr=`expr $maxpack / 100`
[ "$maxerr" -eq 0 ] && maxerr=1

_pmview_cache_fetch -v hinv.ncpu \
    hinv.ndisk \
    disk.all.avg_disk.active \
    mem.util \
    hinv.physmem \
    mem.physmem \
    kernel.all.cpu.wait.total \
    kernel.all.cpu.intr \
    kernel.all.cpu.nice \
    kernel.all.cpu.sys \
    kernel.all.cpu.user

_pmview_cache_fetch -I network.interface.in.bytes \
    disk.ctl.avg_disk.active

if _pmview_fetch_values hinv.ncpu
then
    ncpu=`cat $tmp.pmview_result`
    maxcpu=`expr $maxcpu \* $ncpu`
    maxload=`expr $ncpu \* 2`
else
    _pmview_fetch_fail "get the number of CPUs"
fi

if [ $ncpu -eq 1 ]
then
    cpudesc="1 CPU"
else
    cpudesc="$ncpu CPUs"
fi

$verbose && echo "# $cpudesc detected" >> $tmp.conf

if _pmview_fetch_indom network.interface.in.bytes
then
    ninterfaces=$number
else
    _pmview_fetch_warn "get the number of network interfaces"
    ninterfaces=0
fi

[ $ninterfaces -gt 0 ] && sed < $tmp.pmview_result -e 's/lo[0-9]*//g' -e 's/sl[0-9]*//g' -e 's/ppp[0-9]*//g' > $tmp.list

[ ! -s $tmp.list ] && ninterfaces=0

if $verbose
then
    echo "# Available Network Interfaces: "`cat $tmp.list | tr '\012' ' '` >> $tmp.conf
fi

if [ $ninterfaces -gt 0 ]
then
    if [ -z "$argInterfaces" ]
    then
    	cp $tmp.list $tmp.chosen
    else
    	touch $tmp.chosen
        for i in $argInterfaces
    	do
	    egrep $i $tmp.list >> $tmp.chosen
    	done
    fi

    interfaces_sp=`cat $tmp.chosen | sort | uniq`
    interfaces=`echo $interfaces_sp | sed -e 's/ /,/g'`
    ninterfaces=`echo $interfaces | wc -w`

    if $verbose
    then
	echo "# Network interfaces Matching \"$argInterfaces\": $interfaces" >> $tmp.conf
    fi

    if [ $ninterfaces -eq 0 ]
    then
    	echo "$prog: no matching network interfaces for \"$argInterfaces\"" > $tmp.msg
    	echo "Available network interfaces on host \"$host\" are: " >> $tmp.msg
	tr < $tmp.list '\012' ' ' | fmt | sed -e "s/^/	/" >> $tmp.msg
    	_pmview_error -f $tmp.msg
	#NOTREACHED
    fi
fi

if _pmview_fetch_values hinv.ndisk
then
    ndisk=`cat $tmp.pmview_result`
    maxdiskscale=`expr $maxdisk \* 10`
else
    ndisk=0
    maxdiskscale=0
fi

if [ $ndisk -eq 1 ]
then
    diskdesc="1 Disk"
else
    diskdesc="$ndisk Disks"
fi

$verbose && echo "# $diskdesc detected" >> $tmp.conf

if [ "$ndisk" -gt 0 ]
then
 	
    if _pmview_fetch_values disk.all.avg_disk.active
    then
        allAvg=true
    else
        allAvg=false
    fi

    if _pmview_fetch_indom disk.ctl.avg_disk.active
    then
	nctrl=$number
	cp $tmp.pmview_result $tmp.ctrls
    else
	nctrl=0
    fi

    if [ $nctrl -eq 1 ]
    then
	ctrldesc="1 Disk Controller"
    else
	ctrldesc="$nctrl Disk Controllers"
    fi

    if [ "$nctrl" -gt 0 ]
    then

    	collen=`expr $ninterfaces + 3`
    	collensq=`expr $collen \* $collen`

	if [ $nctrl -le $collen ]
	then
    	    ctrlcols=$nctrl
	elif [ $nctrl -le $collensq ]
	then
    	    ctrlcols=$collen
	else
    	    ctrlcols=`echo $nctrl \
		| $PCP_AWK_PROG '{x = sqrt($1); y = int(x); if (y < x) y++; print y }'`
	fi
    fi

    if $verbose
    then
	echo "# $ctrldesc detected: "`tr < $tmp.ctrls ' ' '\012'` >> $tmp.conf
	echo "#" >> $tmp.conf
    fi
fi

linuxutilmem=false
utilmem=false
if _pmview_fetch_values mem.util.used
then
  linuxutilmem=true
  if $verbose
  then
    echo "# Linux memory utilization metrics supported" >> $tmp.conf
    echo "#" >> $tmp.conf
  fi
else
  linuxutilmem=false
  if _pmview_fetch_values mem.util
  then
    utilmem=true
    if $verbose
    then
    	echo "# Memory utilization metrics supported" >> $tmp.conf
	echo "#" >> $tmp.conf
    fi
  else
    utilmem=false
    if $verbose
    then
	_pmview_warning "$prog: Memory utilization metrics not supported, showing free memory only"
	echo "# Memory utilization metrics not supported, showing free memory only" >> $tmp.conf
	echo "#" >> $tmp.conf
    fi
  fi
fi

# Use mem.physmem if available, otherwise hinv.physmem will do.
if _pmview_fetch_values mem.physmem
then
    realmem=`cat $tmp.pmview_result`
elif _pmview_fetch_values hinv.physmem
then
    realmem=`cat $tmp.pmview_result`
    realmem=`expr $realmem \* 1024`
else
    realmem=0

    if $utilmem
    then
    	if $verbose
	then
	    echo "# Unable to determine total real memory" >> $tmp.conf
	    echo "# Showing memory utilisation with free memory" >> $tmp.conf
	fi
    else
    	_pmview_warning "Unable to determine size of real memory on host \"$host\""
    fi
fi

have_wait=false
if _pmview_fetch_values kernel.all.cpu.wait.total
then
  have_wait=true
fi

have_intr=false
if _pmview_fetch_values kernel.all.cpu.intr
then
  have_intr=true
fi

have_nice=false
if _pmview_fetch_values kernel.all.cpu.nice
then
  have_nice=true
# linux hack !!
# these metrics are not actually supported in linux
  have_intr=false
  have_wait=false
fi

have_sys=false
if _pmview_fetch_values kernel.all.cpu.sys
then
  have_sys=true
fi

have_user=false
if _pmview_fetch_values kernel.all.cpu.user
then
  have_user=true
fi

cpucolors="("
$have_user && cpucolors="$cpucolors blue2"
$have_sys  && cpucolors="$cpucolors red2"
$have_nice && cpucolors="$cpucolors rgbi:0.6/1.0/0.7"
$have_intr && cpucolors="$cpucolors yellow2"
$have_wait && cpucolors="$cpucolors cyan2"
cpucolors="$cpucolors )"

if [ -z "$titleArg" ]
then
    titleArg="SGI PCP : High-Level Activity for Host $host"
fi

cat << end-of-file >> $tmp.conf

_colorlist cpu_colors $cpucolors
_colorlist disk_colors ( violet yellow )
_colorlist ctrl_colors ( green2 )
_colorlist network_colors ( green2 blue2 red2 )

_colorlist memory_colors (
    rgbi:1.0/1.0/0.0
    rgbi:0.0/1.0/1.0
    rgbi:1.0/0.0/0.0
    rgbi:1.0/0.0/1.0
    rgbi:0.0/0.0/1.0
    rgbi:0.0/1.0/0.0
)

_grid hide (

#
# System level stuff
#
end-of-file

if [ "$ndisk" -gt 0 ]
then
    cat << end-of-file >> $tmp.conf

    _label 0 1 _down _large "Disk"

    _stack 1 1 _west _cylinder (
	_metrics (
	    disk.all.write		$maxio
	    disk.all.read		$maxio
	)
	_colorlist disk_colors
	_baseLabel "Disk Operations\nNormalized to $maxio I/Os per second"
    )
end-of-file
 
    if $allAvg
    then
	cat << end-of-file >> $tmp.conf

    _bar 2 1 _west _cylinder (
	_metrics (
	    disk.all.avg_disk.active	$maxdiskscale
	)
	_colorlist ctrl_colors
	_baseLabel "Disk Activity\nNormalized to ${maxdisk}% for $ndisk disks"
    )
end-of-file
    fi

    if [ "$nctrl" -gt 0 ]
    then
	cat << end-of-file >> $tmp.conf

    _label 4 0 _west "Disk Controllers"

    _bar 4 1 _west _cylinder (
	_metrics (
end-of-file

	cat $tmp.ctrls | tr '\012' ' ' \
	| $PCP_AWK_PROG -v cols=$ctrlcols -v scale=$maxdiskscale >> $tmp.conf '
BEGIN	{ str = ""; j = 0 }
	{ for (i = 1; i <= NF; i++) {
	    if (str == "")
	      str = $i;
	    else
	      str = str "," $i
     	    if (j == cols) {
	      printf("            disk.ctl.avg_disk.active[%s] %d\n", str, scale);
	      str = "";
	      j = 0;
	    }
	    else
	      j++;
 	  }
	}
END	{ if (str != "")
	    printf("            disk.ctl.avg_disk.active[%s] %d\n", str, scale);
	}'

	cat << end-of-file >> $tmp.conf
	)
	_colorlist ctrl_colors
	_baseLabel "Disk Controller Activity\nNormalized to ${maxdisk}% for the disks on each controller"
    )
end-of-file

    fi
fi

cat << end-of-file >> $tmp.conf

    _label 0 3 _west _down _large "Load"

    _bar 1 3 2 1 _west (
	_metrics (
	    kernel.all.load[15]	$maxload
	    kernel.all.load[5]	$maxload
	    kernel.all.load[1]	$maxload
	)
	_metriclabels _away ( "15" "5" "1" )
	_colorlist ( blue2 blue2 blue2 )
	_baseLabel "Average System Load over the last 1, 5, and 15 minutes\nNormalized to $maxload"
    )

    _label 0 5 _west _down _large "Mem"

end-of-file

if [ $realmem -ne 0 ]
then
  if $utilmem
  then
  cat << end-of-file >> $tmp.conf
    _stack 1 5 _west (
	_metrics (
	    mem.util.kernel	 	$realmem
	    mem.util.fs_ctl		$realmem
	    mem.util.fs_dirty		$realmem
	    mem.util.fs_clean		$realmem
	    mem.util.user 		$realmem
	)
	_colorlist memory_colors
	_baseLabel "Physical Memory Utilization\nNormalized to $realmem Kbytes"
    )
end-of-file
  elif $linuxutilmem
  then
  cat << end-of-file >> $tmp.conf
    _stack 1 5 _west (
	_metrics (
	    mem.util.shared     $realmem
	    mem.util.cached     $realmem
	    mem.util.bufmem     $realmem
	    mem.util.other      $realmem
	    mem.util.free       $realmem
	)
	_colorlist memory_colors
	_baseLabel "Physical Memory Utilization\nNormalized to `expr $realmem / 1024` Kbytes"
    )
end-of-file
  else
  cat << end-of-file >> $tmp.conf
    _stack 1 5 _west _fillmod (
	_metrics (
	    mem.freemem		$realmem
	)
	_colorlist ( blue2 )
	_baseLabel "Unallocated Physical Memory"
	_stackLabel "Used Physical Memory\nNormalized to $realmem Kbytes"
    )
end-of-file
fi
elif $utilmem
then
  cat << end-of-file >> $tmp.conf
    _stack 1 5 _west _utilmod (
	_metrics (
	    mem.util.kernel 	0
	    mem.util.fs_ctl 	0
	    mem.util.fs_dirty 	0
	    mem.util.fs_clean 	0
	    mem.util.user 	0
	    mem.util.free 	0
	)
	_colorlist memory_colors
	_baseLabel "Physical Memory Utilization"
    )
end-of-file
elif $linuxutilmem
then
  cat << end-of-file >> $tmp.conf
    _stack 1 5 _west _utilmod (
	_metrics (
	    mem.util.shared     0
	    mem.util.cached     0
	    mem.util.bufmem     0
	    mem.util.other      0
	    mem.util.free       0
	)
	_colorlist memory_colors
	_baseLabel "Physical Memory Utilization"
    )
end-of-file
fi

cat << end-of-file >> $tmp.conf

    _label 0 7 _west _down _large "CPU"

    _stack 1 7 _west (
	_metrics (
end-of-file
$have_user && echo "	    kernel.all.cpu.user 	$maxcpu" >> $tmp.conf
$have_sys  && echo "	    kernel.all.cpu.sys		$maxcpu" >> $tmp.conf
$have_nice && echo "	    kernel.all.cpu.nice		$maxcpu" >> $tmp.conf
$have_intr && echo "	    kernel.all.cpu.intr 	$maxcpu" >> $tmp.conf
$have_wait && echo "	    kernel.all.cpu.wait.total 	$maxcpu" >> $tmp.conf
cat << end-of-file >> $tmp.conf
	)
	_colorlist cpu_colors
	_baseLabel "CPU Utilization\nSummed over $cpudesc"
    )
end-of-file

if [ "$ninterfaces" -gt 0 ]
then
    cat << end-of-file >> $tmp.conf

#
# Network Stuff and Alarms
#

    _marginWidth 1

    _grid 4 2 1 7 _nw ( 

	_marginWidth 8

	_label 0 0 _sw "Network Input"

	_bar 0 1 _nw _groupByMetric (
	    _metrics (
		network.interface.in.bytes[$interfaces]	$maxbyte
		network.interface.in.packets[$interfaces]	$maxpack
		network.interface.in.errors[$interfaces]	$maxerr
	    )
	    _colorlist network_colors
	    _metricLabels _away ( "Bytes" "Packets" "Errors" )
	    _baseLabel "Input on all Network Interfaces\nNormalized to $maxbyte bytes per second and $maxpack packets per second"
	)

	_label 0 2 _sw "Network Output"

	_bar 0 3 _nw (
	    _metrics (
		network.interface.out.bytes[$interfaces]	$maxbyte
		network.interface.out.packets[$interfaces] $maxpack
		network.interface.out.errors[$interfaces]  $maxerr
	    )
	    _instlabels _away ( $interfaces_sp )
	    _metricLabels _away ( "Bytes" "Packets" "Errors" )
	    _colorlist network_colors
	    _baseLabel "Output on all Network Interfaces\nNormalized to $maxbyte bytes per second and $maxpack packets per second"
	)
    )
end-of-file
fi

echo ")" >> $tmp.conf

$verbose && cat $tmp.conf

eval $PMVIEW <$tmp.conf $args -title "'$titleArg'" -xrm "'*iconName:osvis'" -R $PCP_VAR_DIR/config/pmlogger/config.osvis

exit