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 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 ef851f0c Lars Kruse
procs=${procs:-}
27 0eaefd6b Erik Cederstrand
28
29 ef851f0c Lars Kruse
if [ "$1" = "autoconf" ] ; then
30 0eaefd6b Erik Cederstrand
    if [ -n "$procs" ] ; then
31
        echo "yes"
32
    else
33 b59ec071 Lars Kruse
        echo "no (environment variable 'procs' is not defined)"
34 0eaefd6b Erik Cederstrand
    fi
35
    exit
36
fi
37
38
if [ "$1" = "config" ] ; then
39 ef851f0c Lars Kruse
    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 0eaefd6b Erik Cederstrand
        echo 'graph_vlabel %'
44
        echo 'graph_scale no'
45
        echo 'graph_period second'
46
47
    echo "graph_order $procs"
48 ef851f0c Lars Kruse
49
    FIRSTPROC=1
50
    for proc in $procs; do
51 0eaefd6b Erik Cederstrand
        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 ef851f0c Lars Kruse
            export FIRSTPROC=0
57
        else
58 0eaefd6b Erik Cederstrand
            echo "${proc}.draw STACK"
59
        fi
60 ef851f0c Lars Kruse
    done
61
62 0eaefd6b Erik Cederstrand
    exit
63
fi
64
65
66
67
for proc in $procs ; do {
68
69 ef851f0c Lars Kruse
    ps axo 'pcpu,comm' | grep "$proc" | awk '
70 0eaefd6b Erik Cederstrand
    BEGIN {
71
        FS=" "
72
        CPU_PROC=0
73
    }
74
75
    {
76
        CPU_PROC+=$0
77
    }
78
79 ef851f0c Lars Kruse
    END {
80
    print  "'"$proc"'.value "CPU_PROC
81
    }'
82 0eaefd6b Erik Cederstrand
}
83
84 ef851f0c Lars Kruse
done