Projet

Général

Profil

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

root / plugins / cpu / process_count @ 17f78427

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

1 53fbef95 Shaun M
#!/bin/bash
2 387c5a1e Sterfan Osterlitz
#
3
# Plugin to monitor CPU usage, for a selected set of processes. Tested on Linux.
4
#
5
# Author: Stefan Osterlitz
6
# Based on work of Erik Cederstrand
7
#
8
# Usage: Place in /usr/local/etc/munin/plugins/ (or link it there  using ln -s)
9
#        Add this to your /ur/local/etc/munin/plugin-conf.d/plugins.conf:
10
11
#       [process_*]
12
#       env.procs httpd java
13
#
14
#    httpd and java being a list of the processes to monitor. You may use regex expressions for grep, but watch their conversion to field names.
15
#		 ps options may vary.
16
17
#
18
# Parameters understood:
19
#
20
#       config   (required)
21
#       autoconf (optional - used by munin-config)
22
#
23
24
#%# family=auto
25
#%# capabilities=autoconf
26
27
28
29 17f78427 Lars Kruse
if [ "$1" = "autoconf" ] ; then
30 387c5a1e Sterfan Osterlitz
    if [ -n "$procs" ] ; then
31
        echo "yes"
32
    else
33
        echo "\$procs not defined."
34
    fi
35
    exit
36
fi
37
38
for proc in $procs; do
39
    cproc=${proc//[^A-Za-z0-9_]/_}
40
    cprocs+=" $cproc"
41
done;
42
43
if [ "$1" = "config" ] ; then
44
    echo "graph_args --base 1000 -r --lower-limit 0";
45
    echo "graph_title Process count";
46
    echo "graph_category processes";
47
    echo "graph_info This graph shows process count, for monitored processes.";
48
        echo 'graph_vlabel number of processes'
49
        echo 'graph_scale no'
50
        echo 'graph_period second'
51
		    echo "graph_order $cprocs"
52 17f78427 Lars Kruse
53
    for proc in $procs; do
54 387c5a1e Sterfan Osterlitz
		cproc=${proc//[^A-Za-z0-9_]/_}
55
        echo "${cproc}.label $proc"
56
        echo "${cproc}.info CPU used by process $proc"
57
     done ;
58 17f78427 Lars Kruse
59 387c5a1e Sterfan Osterlitz
    exit
60
fi
61
62
for proc in $procs ; do {
63
	cproc=${proc//[^A-Za-z0-9_]/_}
64
	ps axo '%mem,comm,command' | grep -v grep | grep "$proc" | LC_ALL=us_US awk '
65 17f78427 Lars Kruse
	BEGIN {
66
	SUM=0
67 387c5a1e Sterfan Osterlitz
	}
68 17f78427 Lars Kruse
        {
69 387c5a1e Sterfan Osterlitz
        SUM+=1
70
        COMM=$2
71
        }
72
        END {
73
        print "'${cproc}'.value "SUM
74
        }
75
        '
76
}
77
78
done;