From 0eaefd6bb8f7642ed2a0004d663d201bdf9e957f Mon Sep 17 00:00:00 2001 From: Erik Cederstrand Date: Thu, 5 May 2011 12:58:24 +0200 Subject: [PATCH] Initial version --- plugins/other/cpu-usage-by-process | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100755 plugins/other/cpu-usage-by-process diff --git a/plugins/other/cpu-usage-by-process b/plugins/other/cpu-usage-by-process new file mode 100755 index 00000000..0b74a3e8 --- /dev/null +++ b/plugins/other/cpu-usage-by-process @@ -0,0 +1,84 @@ +#!/bin/sh +# +# Plugin to monitor CPU usage, for a selected set of processes. Tested on FreeBSD. +# +# Author: Erik Cederstrand +# Based on http://waste.mandragor.org/munin_tutorial/cpubyuser +# Thanks to Yann Hamon. +# +# Usage: Place in /usr/local/etc/munin/plugins/ (or link it there using ln -s) +# Add this to your /ur/local/etc/munin/plugin-conf.d/plugins.conf: +# [cpubyproc] +# env.procs httpd java +# +# httpd and java being a list of the processes to monitor. + +# +# Parameters understood: +# +# config (required) +# autoconf (optional - used by munin-config) +# + +#%# family=auto +#%# capabilities=autoconf + + + +if [ "$1" = "autoconf" ] ; then + if [ -n "$procs" ] ; then + echo "yes" + else + echo "\$procs not defined." + fi + exit +fi + +if [ "$1" = "config" ] ; then + echo "graph_args --base 1000 -r --lower-limit 0"; + echo "graph_title CPU usage, by process"; + echo "graph_category system"; + echo "graph_info This graph shows CPU usage, for monitored processes."; + echo 'graph_vlabel %' + echo 'graph_scale no' + echo 'graph_period second' + + echo "graph_order $procs" + + FIRSTPROC=1; + for proc in $procs; do + echo "${proc}.label $proc" + echo "${proc}.info CPU used by process $proc" + echo "${proc}.type GAUGE" + if [ $FIRSTPROC -eq 1 ] ; then + echo "${proc}.draw AREA" + export FIRSTPROC=0; + else + echo "${proc}.draw STACK" + fi + done ; + + exit +fi + + + +for proc in $procs ; do { + + ps -axo 'pcpu,comm' | grep "$proc" | + awk ' + BEGIN { + FS=" " + CPU_PROC=0 + } + + { + CPU_PROC+=$0 + } + + END { + print "'$proc'.value "CPU_PROC + }' +} + +done;