Projet

Général

Profil

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

root / plugins / system / multicpu1sec / multicpu1sec @ 6dec8c33

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