root / plugins / cpu / process_count @ 17f78427
Historique | Voir | Annoter | Télécharger (1,74 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
# |
| 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 |
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 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 |
|
| 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 |
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 |
BEGIN {
|
| 66 |
SUM=0 |
| 67 |
} |
| 68 |
{
|
| 69 |
SUM+=1 |
| 70 |
COMM=$2 |
| 71 |
} |
| 72 |
END {
|
| 73 |
print "'${cproc}'.value "SUM
|
| 74 |
} |
| 75 |
' |
| 76 |
} |
| 77 |
|
| 78 |
done; |
