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 (108 lines) | stat: -rw-r--r-- 2,893 bytes parent folder | download | duplicates (4)
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
#!@@GOODSH@@
#
# Plugin to monitor CPU usage.
#
# Usage: Place in /etc/munin/node.d/ (or link it there  using ln -s)
#
# Parameters understood:
#
# 	config   (required)
# 	autoconf (optional - used by munin-config)
#
# Magic markers - optional - used by installation scripts and
# munin-config:
#
#%# family=auto
#%# capabilities=autoconf

SYSCTL_BIN=$(command -v sysctl)

if [ "$1" = "autoconf" ]; then
	if [ ! -z "$SYSCTL_BIN" ]; then
		$SYSCTL_BIN kern.cp_time > /dev/null
		if [ $? = "0" ]; then
			echo yes
			exit 0
		else
			echo no
			exit 0
		fi
	else
		echo no
		exit 0
	fi
fi

if [ "$1" = "config" ]; then

	OSV=`$SYSCTL_BIN -n kern.osrelease | cut -f1 -d.`
	if [ "$OSV" = "4" ]; then
		STATUNITS=`$SYSCTL_BIN -n kern.clockrate | cut -f16 -d' '`
	elif [ "$OSV" -ge "5" ]; then
		STATUNITS=`$SYSCTL_BIN -n kern.clockrate | cut -f13 -d' '`
	fi
	PERCENT=`$SYSCTL_BIN -n hw.ncpu | awk '{print ($1)*100}'`
	NCPU=`$SYSCTL_BIN -n hw.ncpu`
	if [ "$scaleto100" = yes ]; then
		CDEF="$STATUNITS,/,100,*,$NCPU,/"
		PERCENT=100
	else
		CDEF="$STATUNITS,/,100,*"
		PERCENT=$(($NCPU*100))
	fi
#	SYSWARNING=$PERCENT*30/100
#	SYSCRITICAL=$PERCENT*50/100
#	INTWARNING=$PERCENT*80/100
#	USRWARNING=$PERCENT*80/100
	echo 'graph_title CPU usage'
	echo 'graph_order system interrupt user nice idle'
	echo "graph_args --base 1000 -r --lower-limit 0 --upper-limit $PERCENT "
	echo 'graph_vlabel %'
	echo 'graph_scale no'
	echo 'graph_info This graph shows how CPU time is spent.'
	echo 'graph_category system'
	echo 'graph_period second'
	echo 'system.label system'
	echo 'system.draw AREA'
	echo 'system.max 5000'
	echo 'system.type DERIVE'
	echo 'system.min 0'
#	echo "system.warning $SYSWARNING"
#	echo "system.critical $SYSCRITICAL"
	echo 'system.info CPU time spent by the kernel in system activities'
	echo "system.cdef system,$CDEF"
	echo 'interrupt.label interrupt'
	echo 'interrupt.draw STACK'
	echo 'interrupt.max 5000'
#	echo "interrupt.warning $INTWARNING"
	echo 'interrupt.type DERIVE'
	echo 'interrupt.min 0'
	echo 'interrupt.info CPU time spent by the kernel processing interrupts'
	echo "interrupt.cdef interrupt,$CDEF"
	echo 'user.label user'
	echo 'user.draw STACK'
	echo 'user.max 5000'
#	echo "user.warning $USRWARNING"
	echo 'user.type DERIVE'
	echo 'user.info CPU time spent by normal programs and daemons'
	echo 'user.min 0'
	echo "user.cdef user,$CDEF"
	echo 'nice.label nice'
	echo 'nice.draw STACK'
	echo 'nice.max 5000'
	echo 'nice.type DERIVE'
	echo 'nice.info CPU time spent by nice(1)d programs'
	echo 'nice.min 0'
	echo "nice.cdef nice,$CDEF"
	echo 'idle.label idle'
	echo 'idle.draw STACK'
	echo 'idle.max 5000'
	echo 'idle.type DERIVE'
	echo 'idle.info Idle CPU time'
	echo 'idle.min 0'
	echo "idle.cdef idle,$CDEF"
	exit 0
fi

$SYSCTL_BIN kern.cp_time | awk '{ print "user.value " $2 "\nnice.value " $3 "\nsystem.value " $4 "\ninterrupt.value " $5 "\nidle.value " $6 }'