root / plugins / http / mongrel_process_memory @ 17f78427
Historique | Voir | Annoter | Télécharger (2,47 ko)
| 1 |
#!/usr/bin/env ruby |
|---|---|
| 2 |
# |
| 3 |
# mongrel_process_memory - A munin plugin to monitor memory size of |
| 4 |
# each individual mongrel process |
| 5 |
# Copyright (C) 2007 Ben VandenBos and Avvo, Inc. |
| 6 |
# |
| 7 |
# This program is free software; you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License version 2 |
| 9 |
# as published by the Free Software Foundation. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License along |
| 17 |
# with this program; if not, write to the Free Software Foundation, Inc., |
| 18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 |
# |
| 20 |
# Author: Ben VandenBos |
| 21 |
# Contributors: Adam Jacob (<adam@hjksolutions.com>) |
| 22 |
# Ryan Woodrum |
| 23 |
# |
| 24 |
#%# family=auto |
| 25 |
#%# capabilities=autoconf |
| 26 |
|
| 27 |
module Munin |
| 28 |
class MongrelProcessMemory |
| 29 |
|
| 30 |
def run |
| 31 |
h = get_pids() |
| 32 |
ps_output = "" |
| 33 |
#I have no doubt that this is a terrible way of doing this. |
| 34 |
h.each do |k, v| |
| 35 |
ps_output = ps_output + `ps --no-heading l #{k}`
|
| 36 |
end |
| 37 |
|
| 38 |
if ps_output |
| 39 |
port_list = Hash.new |
| 40 |
ps_output.each_line do |l| |
| 41 |
if l =~ /-p (\d+)/ |
| 42 |
port = $1 |
| 43 |
l_ary = l.split(/\s+/) |
| 44 |
if l_ary.length > 6 |
| 45 |
port_list[port] = l_ary[7].to_i * 1024 |
| 46 |
end |
| 47 |
end |
| 48 |
end |
| 49 |
port_list.sort.each do |port| |
| 50 |
puts "mongrel_#{port[0]}.value #{port[1]}"
|
| 51 |
end |
| 52 |
|
| 53 |
end |
| 54 |
end |
| 55 |
|
| 56 |
def get_pids |
| 57 |
h = Hash.new |
| 58 |
pids = [] |
| 59 |
pids = `pgrep mongrel_rails` |
| 60 |
pids.each { |p|
|
| 61 |
l = `ps #{p}`
|
| 62 |
l =~ /-p (\d+)/ |
| 63 |
h[p] = $1 |
| 64 |
} |
| 65 |
h |
| 66 |
end |
| 67 |
|
| 68 |
def autoconf |
| 69 |
pids.length > 0 |
| 70 |
end |
| 71 |
|
| 72 |
end |
| 73 |
end |
| 74 |
|
| 75 |
mpm = Munin::MongrelProcessMemory.new |
| 76 |
|
| 77 |
case ARGV[0] |
| 78 |
when "config" |
| 79 |
puts "graph_title Mongrel Memory" |
| 80 |
puts "graph_vlabel RSS" |
| 81 |
puts "graph_category memory" |
| 82 |
puts "graph_args --base 1024 -l 0" |
| 83 |
puts "graph_scale yes" |
| 84 |
puts "graph_info Tracks the size of individual mongrel processes" |
| 85 |
mpm.get_pids.values.sort.each do |port| |
| 86 |
puts "mongrel_#{port}.label mongrel_#{port}"
|
| 87 |
puts "mongrel_#{port}.info Process memory"
|
| 88 |
puts "mongrel_#{port}.type GAUGE"
|
| 89 |
puts "mongrel_#{port}.min 0"
|
| 90 |
end |
| 91 |
when "autoconf" |
| 92 |
if mpm.autoconf |
| 93 |
puts "yes" |
| 94 |
exit 0 |
| 95 |
end |
| 96 |
puts "no" |
| 97 |
exit 1 |
| 98 |
else |
| 99 |
mpm.run |
| 100 |
end |
