Projet

Général

Profil

Révision 32715ca3

ID32715ca3a9955fdd584d6c435328b57a9b522c81
Parent 387c5a1e
Enfant 0ca8ce20

Ajouté par Stefan Osterlitz il y a presque 14 ans

Initial version

Voir les différences:

plugins/other/process_cpushare
1
#!/bin/sh
2
#
3
# Plugin to monitor CPU share, 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
if [ "$1" = "autoconf" ] ; then 
30
    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 CPU usage, by process";
46
    echo "graph_category processes";
47
    echo "graph_info This graph shows CPU usage, for monitored processes.";
48
    echo 'graph_vlabel %'
49
    echo 'graph_scale no'
50
    echo 'graph_period second'
51
    echo "graph_order $cprocs"
52
    
53
    for proc in $procs; do  
54
        cproc=${proc//[^A-Za-z0-9_]/_}
55
        echo "${cproc}.label $proc"
56
        echo "${cproc}.info CPU used by process $proc"
57
     done ;
58
    
59
    exit
60
fi
61

  
62

  
63

  
64
for proc in $procs ; do {
65
        cproc=${proc//[^A-Za-z0-9_]/_}
66
	ps axo 'pcpu,comm,command' | grep -v grep | grep "$proc" | LC_ALL=us_US awk '
67
	BEGIN { 
68
	SUM=0 
69
	}
70
	{ 
71
	SUM+=$1 
72
	}
73
	END { 
74
	print "'${cproc}'.value "SUM 
75
	}
76
	'
77
}
78
done;

Formats disponibles : Unified diff