Projet

Général

Profil

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

root / plugins / cpu / cpu-usage-by-process @ ef851f0c

Historique | Voir | Annoter | Télécharger (1,74 ko)

1
#!/bin/sh
2
#
3
# Plugin to monitor CPU usage, for a selected set of processes. Tested on FreeBSD.
4
#
5
# Author: Erik Cederstrand
6
# Based on http://waste.mandragor.org/munin_tutorial/cpubyuser
7
# Thanks to Yann Hamon.
8
#
9
# Usage: Place in /usr/local/etc/munin/plugins/ (or link it there  using ln -s)
10
#        Add this to your /ur/local/etc/munin/plugin-conf.d/plugins.conf:
11
#       [cpubyproc]
12
#       env.procs httpd java
13
#
14
#    httpd and java being a list of the processes to monitor.
15

    
16
#
17
# Parameters understood:
18
#
19
#       config   (required)
20
#       autoconf (optional - used by munin-config)
21
#
22

    
23
#%# family=auto
24
#%# capabilities=autoconf
25

    
26
procs=${procs:-}
27

    
28

    
29
if [ "$1" = "autoconf" ] ; then
30
    if [ -n "$procs" ] ; then
31
        echo "yes"
32
    else
33
        echo "no (environment variable 'procs' is not defined)"
34
    fi
35
    exit
36
fi
37

    
38
if [ "$1" = "config" ] ; then
39
    echo "graph_args --base 1000 -r --lower-limit 0"
40
    echo "graph_title CPU usage, by process"
41
    echo "graph_category processes"
42
    echo "graph_info This graph shows CPU usage, for monitored processes."
43
        echo 'graph_vlabel %'
44
        echo 'graph_scale no'
45
        echo 'graph_period second'
46

    
47
    echo "graph_order $procs"
48

    
49
    FIRSTPROC=1
50
    for proc in $procs; do
51
        echo "${proc}.label $proc"
52
        echo "${proc}.info CPU used by process $proc"
53
        echo "${proc}.type GAUGE"
54
        if [ $FIRSTPROC -eq 1 ] ; then
55
            echo "${proc}.draw AREA"
56
            export FIRSTPROC=0
57
        else
58
            echo "${proc}.draw STACK"
59
        fi
60
    done
61

    
62
    exit
63
fi
64

    
65

    
66

    
67
for proc in $procs ; do {
68

    
69
    ps axo 'pcpu,comm' | grep "$proc" | awk '
70
    BEGIN {
71
        FS=" "
72
        CPU_PROC=0
73
    }
74

    
75
    {
76
        CPU_PROC+=$0
77
    }
78

    
79
    END {
80
    print  "'"$proc"'.value "CPU_PROC
81
    }'
82
}
83

    
84
done