Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / cpu / multicpu1sec @ 17f78427

Historique | Voir | Annoter | Télécharger (2 ko)

1 8a955385 Steve Schnepp
#!/bin/bash
2 3b64d836 Steve Schnepp
# (c) 2012  - Bushmills
3
# License : GPLv2
4 8a955385 Steve Schnepp
5
#%# family=auto
6
#%# capabilities=autoconf
7
8
9
interval=1			# mpstat sampling interval
10
timeout=1200			# 20 minutes daemon watchdog timeout
11
watchdog=60			# test for timeout every $watchdog seconds
12
pluginfull="$0"                 # full name of plugin
13
plugin="${0##*/}"	        # name of plugin
14
pidfile="$MUNIN_PLUGSTATE/munin.$plugin.pid"
15
cache="$MUNIN_PLUGSTATE/munin.$plugin.value"
16
graph="$plugin"
17
style="AREA"
18
cpus=$(grep -c ^processor /proc/cpuinfo)
19
20 17f78427 Lars Kruse
run_watchdog()  {                 # should also trap kill and term signals
21 ad72df15 Steve Schnepp
   kill -0 $(cat $pidfile) 2> /dev/null || rm -f $pidfile
22 8a955385 Steve Schnepp
}
23
24
25
run_acquire()  {
26
   echo "$$" > $pidfile
27 5090a771 Steve Schnepp
   LANG=C mpstat -P ALL $interval |
28 729c6123 Steve Schnepp
   awk -v cpus=$cpus '$2>=0&&$2<99 {print $2, systime(), (100-$11)/cpus; system("");}' >> $cache
29 8a955385 Steve Schnepp
   rm -f $pidfile $cache
30
}
31
32
run_daemon()  {
33 ad72df15 Steve Schnepp
   run_watchdog
34 8a955385 Steve Schnepp
   if [ -f $pidfile ]; then
35
      touch $pidfile
36 17f78427 Lars Kruse
   else
37 8a955385 Steve Schnepp
      $pluginfull acquire &
38
   fi
39
}
40
41
42
# --------------------------------------------------------------------------
43
44
run_autoconf() {
45
   run=(yes no)
46
   type -t mpstat > /dev/null
47
   echo "${run[$?]}"
48
}
49
50
run_config() {
51
run_daemon
52
cat << EOF
53
graph_title $graph
54 34eeebbe Lars Kruse
graph_category 1sec
55 8a955385 Steve Schnepp
graph_vlabel average cpu use %
56
graph_scale no
57 17f78427 Lars Kruse
graph_total All CPUs
58 8a955385 Steve Schnepp
update_rate 1
59 17f78427 Lars Kruse
graph_data_size custom 1d, 10s for 1w, 1m for 1t, 5m for 1y
60 8a955385 Steve Schnepp
EOF
61
cpun=0
62
for ((i=0; i<$cpus; i++)); do
63
cat << EOF
64
cpu${cpun}.label CPU $cpun
65
cpu${cpun}.draw $style
66
cpu${cpun}.min 0
67
EOF
68
style=STACK
69
((cpun++))
70
done
71
}
72
73
run_fetch()  {
74
   run_daemon
75
   awk 'NF==3 {print "cpu" $1 ".value " $2 ":" $3}' $cache
76
   > $cache
77
}
78
79
80
run_${1:-fetch}
81
exit 0
82
83
# export -f functionname     export functionname to subshell, avoiding the need
84
#    for locating plugin for subshell calling, when process needs a different
85
#    pid. Instead, $SHELL -c functionname  can be used. useful for calling
86
#    acquire which needs a different pid than watchdog, otherwise watchdog
87
#    could/will kill itself when expiring before the watched process is killed.
88
# not a POSIX feature.