From 59365297433c2faa72e97b500fd92b68d6686bbb Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 8 Jun 2010 16:56:35 +0200 Subject: [PATCH] Initial version --- plugins/other/cpu_by_process | 135 +++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100755 plugins/other/cpu_by_process diff --git a/plugins/other/cpu_by_process b/plugins/other/cpu_by_process new file mode 100755 index 00000000..41d33d53 --- /dev/null +++ b/plugins/other/cpu_by_process @@ -0,0 +1,135 @@ +#!/bin/sh +# +# Copyright (C) 2006 Holger Levsen +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; version 2 dated June, +# 1991. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# Configuration variables +# vservers - specify the vservers to include in the graph (default: all) +# limits - if true, turn on limit graphing (default: false) +# +# NOTE: If no configuration variables are set, the defaults will be used + +# Example /etc/munin/plugin-conf.d/munin-node +# +# The first group monitors the vservers named "vserver1 vserver2 +# vserver3 vserver4" and looks to see if the resource limit has been +# breached, if so it sends a message to nagios via send_nsca, and +# sends an email to notify that this has happened. +# +# The second monitors the vservers "vserver5 vserver6 vserver7" and +# has no limit notifications turned on. +# +# The third monitors all vservers on the system, in one graph, and it has +# no limit notifications defined. +# +# You can use any combination of these to fit your needs. +# +# +# [vsrmem_group1] +# user root +# env.vservers vserver1 vserver2 vserver3 vserver4 +# env.limits 1 +# contacts nagios email +# contact.nagios.command /usr/bin/send_nsca -H your.nagios-host.here -c /etc/send_nsca.cfg +# contact.email.command mail -s "Munin-notification for ${var:group} :: ${var:host}" your@email.address.here +# +# [vsrmem_group2] +# user root +# env.vservers vserver5 vserver6 vserver7 +# env.limits 0 +# +# [vserver_rmemory] +# user root +# +# Graph Vserver RSS usage and limits +# +# Changelog +# version 0.1 - 2006 April xx - Holger Levsen +# - initial author +# version 0.2 - 2006 April 24 - Micah Anderson +# - Add dynamic arch page size determination +# - Some cleanup and clarification +# version 0.3 - 2006 May 3 - Micah Anderson +# - Add ability to group vservers via environment vars +# - Fix missing close quotes and standardize indents +# - Add limit notification +# - Update documentation to include info on groups and limits +# version 0.4 - 2006 Jun 22 - Micah Anderson +# - Fix error that results if NodeName is set to include a domain name + +#scriptname=`basename $0` +#vsname=`echo $scriptname | perl -ne '/^vserver_proc_VM_(.*)/ and print $1'` + +#if [ "$1" = "suggest" ]; then +# ls -1 /etc/vservers +# exit 0 +#elif [ -z "$vsname" ]; then +# echo "Must be used with a vserver name; try '$0 suggest'" >&2 +# exit 2 +#fi + +#xid=`cat /etc/vservers/$vsname/context` + +if [ "$1" = "config" ]; then + echo "graph_title CPU time by Process" + echo 'graph_args --base 1000 -l 0' + echo 'graph_vlabel seconds' + echo 'graph_category system' + echo "graph_info Shows CPU time used by each process name" + + # ps -eo time,comm h | perl -e ' + ps -eo pid,time,comm | perl -e ' + $junk = <>; + while (<>) + { + @a = split; + $proc = $a[2]; + $var = $proc; + $var =~ s|/.*||; + $var =~ s|\.$||; + $var =~ tr|a-zA-Z0-9|_|c; + $procs{$var} = $proc; + } + my $stack = 0; + sub draw() { return $stack++ ? "STACK" : "AREA" } + print map + { + "$_.label $procs{$_}\n" . + "$_.min 0\n" . + "$_.type DERIVE\n" . + "$_.draw " . draw() . "\n" + } + sort keys %procs; + ' + exit 0 +else + # ps -eo time,comm h | perl -e ' + ps -eo pid,time,comm | perl -e ' + $junk = <>; + while (<>) + { + @a = split; + $cpu = $a[1]; + $var = $a[2]; + $var =~ s|/.*||; + $var =~ s|\.$||; + $var =~ tr|a-zA-Z0-9|_|c; + @b = split /:/, $cpu; + $cpu = (($b[0] * 60) + $b[1]) * 60 + $b[2]; + $total{$var} += $cpu; + } + print map {"$_.value $total{$_}\n"} sort keys %total' +fi