Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / http / mongrel_process_memory @ b0b39b01

Historique | Voir | Annoter | Télécharger (2,45 ko)

1
#!/usr/bin/env ruby
2

    
3
=begin
4

    
5
mongrel_process_memory - A munin plugin to monitor memory size of
6
                         each individual mongrel process
7
Copyright (C) 2007 Ben VandenBos and Avvo, Inc.
8

    
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License version 2
11
as published by the Free Software Foundation.
12

    
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
GNU General Public License for more details.
17

    
18
You should have received a copy of the GNU General Public License along
19
with this program; if not, write to the Free Software Foundation, Inc.,
20
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21

    
22
Author: Ben VandenBos
23
Contributors: Adam Jacob (<adam@hjksolutions.com>)
24
              Ryan Woodrum
25

    
26
#%# family=auto
27
#%# capabilities=autoconf
28

    
29
=end
30

    
31

    
32
module Munin
33
  class MongrelProcessMemory
34
    def run
35
      h = get_pids()
36
      ps_output = ""
37
      # I have no doubt that this is a terrible way of doing this.
38
      h.each do |k, v|
39
        ps_output = ps_output + `ps --no-heading l #{k}`
40
      end
41

    
42
      if ps_output
43
        port_list = Hash.new
44
        ps_output.each_line do |l|
45
          if l =~ /-p (\d+)/
46
            port = $1
47
            l_ary = l.split(/\s+/)
48
            if l_ary.length > 6
49
              port_list[port] = l_ary[7].to_i * 1024
50
            end
51
          end
52
        end
53
        port_list.sort.each do |port|
54
          puts "mongrel_#{port[0]}.value #{port[1]}"
55
        end
56

    
57
      end
58
    end
59

    
60
    def get_pids
61
      h = Hash.new
62
      pids = []
63
      pids = `pgrep mongrel_rails`
64
      pids.each { |p|
65
        l = `ps #{p}`
66
        l =~ /-p (\d+)/
67
        h[p] = $1
68
      }
69
      h
70
    end
71

    
72
    def autoconf
73
      pids.length > 0
74
    end
75
  end
76
end
77

    
78
mpm = Munin::MongrelProcessMemory.new
79

    
80
case ARGV[0]
81
when "config"
82
  puts "graph_title Mongrel Memory"
83
  puts "graph_vlabel RSS"
84
  puts "graph_category memory"
85
  puts "graph_args --base 1024 -l 0"
86
  puts "graph_scale yes"
87
  puts "graph_info Tracks the size of individual mongrel processes"
88
  mpm.get_pids.values.sort.each do |port|
89
    puts "mongrel_#{port}.label mongrel_#{port}"
90
    puts "mongrel_#{port}.info Process memory"
91
    puts "mongrel_#{port}.type GAUGE"
92
    puts "mongrel_#{port}.min 0"
93
  end
94
when "autoconf"
95
  if mpm.autoconf
96
    puts "yes"
97
    exit 0
98
  end
99
  puts "no"
100
  exit 0
101
else
102
  mpm.run
103
end