Projet

Général

Profil

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

root / plugins / system / cpu-usage-by-process @ d0216f00

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

1 0eaefd6b Erik Cederstrand
#!/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
27
28
if [ "$1" = "autoconf" ] ; then 
29
    if [ -n "$procs" ] ; then
30
        echo "yes"
31
    else
32
        echo "\$procs not defined."
33
    fi
34
    exit
35
fi
36
37
if [ "$1" = "config" ] ; then
38
    echo "graph_args --base 1000 -r --lower-limit 0";
39
    echo "graph_title CPU usage, by process";
40
    echo "graph_category system";
41
    echo "graph_info This graph shows CPU usage, for monitored processes.";
42
        echo 'graph_vlabel %'
43
        echo 'graph_scale no'
44
        echo 'graph_period second'
45
46
    echo "graph_order $procs"
47
    
48
    FIRSTPROC=1;
49
    for proc in $procs; do  
50
        echo "${proc}.label $proc"
51
        echo "${proc}.info CPU used by process $proc"
52
        echo "${proc}.type GAUGE"
53
        if [ $FIRSTPROC -eq 1 ] ; then
54
            echo "${proc}.draw AREA"
55
            export FIRSTPROC=0;
56
        else    
57
            echo "${proc}.draw STACK"
58
        fi
59
    done ;
60
    
61
    exit
62
fi
63
64
65
66
for proc in $procs ; do {
67
68 2741a6ef Lars Windolf
    ps axo 'pcpu,comm' | grep "$proc" |
69 0eaefd6b Erik Cederstrand
    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;