Projet

Général

Profil

Révision 59365297

ID59365297433c2faa72e97b500fd92b68d6686bbb
Parent 5bcb8fbc
Enfant 57c0e46b

Ajouté par Chris Wilson il y a presque 14 ans

Initial version

Voir les différences:

plugins/other/cpu_by_process
1
#!/bin/sh
2
#
3
# Copyright (C) 2006 Holger Levsen
4
#
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; version 2 dated June,
8
# 1991.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
#
19
# Configuration variables
20
#   vservers - specify the vservers to include in the graph (default: all)
21
#   limits - if true, turn on limit graphing (default: false)
22
#
23
# NOTE: If no configuration variables are set, the defaults will be used
24

  
25
# Example /etc/munin/plugin-conf.d/munin-node 
26
#
27
# The first group monitors the vservers named "vserver1 vserver2
28
# vserver3 vserver4" and looks to see if the resource limit has been
29
# breached, if so it sends a message to nagios via send_nsca, and
30
# sends an email to notify that this has happened.
31
#
32
# The second monitors the vservers "vserver5 vserver6 vserver7" and 
33
# has no limit notifications turned on.
34
#
35
# The third monitors all vservers on the system, in one graph, and it has
36
# no limit notifications defined.
37
#
38
# You can use any combination of these to fit your needs.
39
#
40
#
41
# [vsrmem_group1]
42
# user root
43
# env.vservers vserver1 vserver2 vserver3 vserver4
44
# env.limits 1
45
# contacts nagios email
46
# contact.nagios.command /usr/bin/send_nsca -H your.nagios-host.here -c /etc/send_nsca.cfg
47
# contact.email.command mail -s "Munin-notification for ${var:group} :: ${var:host}" your@email.address.here
48
#
49
# [vsrmem_group2]
50
# user root
51
# env.vservers vserver5 vserver6 vserver7
52
# env.limits 0
53
#
54
# [vserver_rmemory]
55
# user root
56
#
57
# Graph Vserver RSS usage and limits
58
#
59
# Changelog
60
# version 0.1 - 2006 April xx - Holger Levsen
61
#  - initial author
62
# version 0.2 - 2006 April 24 - Micah Anderson <micah@riseup.net>
63
#  - Add dynamic arch page size determination
64
#  - Some cleanup and clarification
65
# version 0.3 - 2006 May 3 - Micah Anderson <micah@riseup.net>
66
#  - Add ability to group vservers via environment vars
67
#  - Fix missing close quotes and standardize indents
68
#  - Add limit notification
69
#  - Update documentation to include info on groups and limits
70
# version 0.4 - 2006 Jun 22 - Micah Anderson <micah@riseup.net>
71
#  - Fix error that results if NodeName is set to include a domain name
72

  
73
#scriptname=`basename $0`
74
#vsname=`echo $scriptname | perl -ne '/^vserver_proc_VM_(.*)/ and print $1'`
75

  
76
#if [ "$1" = "suggest" ]; then
77
#	ls -1 /etc/vservers
78
#	exit 0
79
#elif [ -z "$vsname" ]; then
80
#	echo "Must be used with a vserver name; try '$0 suggest'" >&2
81
#	exit 2
82
#fi
83

  
84
#xid=`cat /etc/vservers/$vsname/context`
85

  
86
if [ "$1" = "config" ]; then
87
	echo "graph_title CPU time by Process"
88
	echo 'graph_args --base 1000 -l 0'
89
	echo 'graph_vlabel seconds'
90
	echo 'graph_category system'
91
	echo "graph_info Shows CPU time used by each process name"
92

  
93
	# ps -eo time,comm h | perl -e '
94
	ps -eo pid,time,comm | perl -e '
95
		$junk = <>;
96
		while (<>)
97
		{
98
			@a = split;
99
			$proc = $a[2];
100
			$var = $proc;
101
			$var =~ s|/.*||;
102
			$var =~ s|\.$||;
103
			$var =~ tr|a-zA-Z0-9|_|c;
104
			$procs{$var} = $proc;
105
		}
106
		my $stack = 0;
107
		sub draw() { return $stack++ ? "STACK" : "AREA" }
108
		print map
109
		{
110
			"$_.label $procs{$_}\n" .
111
			"$_.min 0\n" .
112
			"$_.type DERIVE\n" .
113
			"$_.draw " . draw() . "\n"
114
		}
115
		sort keys %procs;
116
		'
117
	exit 0
118
else
119
	# ps -eo time,comm h | perl -e '
120
	ps -eo pid,time,comm | perl -e '
121
		$junk = <>;
122
		while (<>)
123
		{
124
			@a = split;
125
			$cpu = $a[1];
126
			$var = $a[2];
127
			$var =~ s|/.*||;
128
			$var =~ s|\.$||;
129
			$var =~ tr|a-zA-Z0-9|_|c;
130
			@b = split /:/, $cpu;
131
			$cpu = (($b[0] * 60) + $b[1]) * 60 + $b[2];
132
			$total{$var} += $cpu;
133
		}
134
		print map {"$_.value $total{$_}\n"} sort keys %total'
135
fi

Formats disponibles : Unified diff