File: cpu.in

package info (click to toggle)
munin 2.0.76-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,064 kB
  • sloc: perl: 11,684; java: 1,924; sh: 1,632; makefile: 636; javascript: 365; python: 267
file content (104 lines) | stat: -rw-r--r-- 2,072 bytes parent folder | download | duplicates (5)
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
#!@@GOODSH@@
# -*- sh -*-

: << =cut

=head1 NAME

cpu - Plugin to monitor CPU usage

=head1 CONFIGURATION

No configuration

=head1 AUTHOR

Unknown author

=head1 LICENSE

GPLv2

=head1 MAGIC MARKERS

 #%# family=auto
 #%# capabilities=autoconf

=cut

. "$MUNIN_LIBDIR/plugins/plugin.sh"

if [ "$1" = "autoconf" ]; then
	if [ -x /usr/bin/kstat ]; then
		echo yes
		exit 0
	else
		echo no
		exit 0
	fi
fi

if [ "$1" = "config" ]; then
	echo 'graph_title CPU usage'
	echo 'graph_order system user waitio idle'
	echo 'graph_category system'
	ncpu=`kstat -p -c misc -n system_misc -s '/^ncpus$/' | cut -f2 -d'	'`
	cpumax=`expr "$ncpu" '*' 100`
	if [ "$scaleto100" = "yes" ]; then
		graphlimit=100
	else
		graphlimit=$cpumax
	fi
	echo "graph_args --base 1000 --lower-limit 0 --rigid --upper-limit $graphlimit"
	echo 'graph_vlabel %'
	echo 'graph_scale no'
	echo 'graph_period ${graph_period}'
	echo 'system.label system'
	echo 'system.draw AREA'
	echo 'system.type DERIVE'
	echo 'system.min 0'
	echo "system.max $cpumax"
	print_adjusted_thresholds system "$graphlimit"
	echo 'user.label user'
	echo 'user.draw STACK'
	echo 'user.type DERIVE'
	echo 'user.min 0'
	echo "user.max $cpumax"
	print_adjusted_thresholds user "$graphlimit"
	echo "waitio.max $cpumax"
	echo 'waitio.label waitio'
	echo 'waitio.draw STACK'
	echo 'waitio.type DERIVE'
	echo 'waitio.min 0'
	print_adjusted_thresholds waitio "$graphlimit"
	echo 'idle.label idle'
	echo 'idle.draw STACK'
	echo 'idle.type DERIVE'
	echo 'idle.min 0'
	echo "idle.max $cpumax"
	print_adjusted_thresholds idle "$graphlimit"
	if [ "$scaleto100" = "yes" ]; then
		echo "system.cdef system,$ncpu,/"
		echo "user.cdef user,$ncpu,/"
		echo "waitio.cdef waitio,$ncpu,/"
		echo "idle.cdef idle,$ncpu,/"
	fi
	exit 0
fi

kstat -p -c misc -m cpu_stat -s '/^(user|kernel|wait|idle)$/' | sed -e 's/.*://' | awk '
BEGIN {
	map["user"] = "user"
	map["kernel"] = "system"
	map["wait"] = "waitio"
	map["idle"] = "idle"
}
length(map[$1]) > 0 {
	sum[map[$1]] += $2
	total += $2
}
END {
	for (item in sum) {
		print item ".value", sum[item]
	}
}'