Projet

Général

Profil

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

root / plugins / http / mongrel_memory @ 17f78427

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

1
#!/usr/bin/env ruby
2
# mongrel_memory - A munin plugin for OpenSolaris to monitor memory size of
3
#                  each individual mongrel process
4
# Copyright (C) 2009 Matthias Marschall - mm@agileweboperations.com
5
#
6
# Based on:
7
# mongrel_process_memory - A munin plugin to monitor memory size of
8
#                          each individual mongrel process
9
# Copyright (C) 2007 Ben VandenBos and Avvo, Inc.
10
#
11
# This program is free software; you can redistribute it and/or modify
12
# it under the terms of the GNU General Public License version 2
13
# as published by the Free Software Foundation.
14
#
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
# GNU General Public License for more details.
19
#
20
# You should have received a copy of the GNU General Public License along
21
# with this program; if not, write to the Free Software Foundation, Inc.,
22
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
#
24
# Author: Ben VandenBos
25
# Contributors: Adam Jacob (<adam@hjksolutions.com>)
26
#               Ryan Woodrum
27
#               Matthias Marschall (mm@agileweboperations.com)
28
#
29
#%# family=auto
30
#%# capabilities=autoconf
31

    
32
module Munin
33
  class MongrelProcessMemory
34

    
35
    def run
36
      pid_port_map = get_pids()
37
      port_list = Hash.new
38
      pid_port_map.sort.each do |pid, port|
39
        rss = `pmap -x #{pid} | grep total`.split(" ")[3]
40
        puts "mongrel_#{port}.value #{rss}"
41
      end
42
    end
43

    
44
    def get_pids
45
      h = Hash.new
46
      pids = []
47
      pids += `pgrep mongrel_rails`.split("\n")
48
      pids += `pgrep ruby`.split("\n")
49
      pids.each { |pid|
50
        l = `pargs -l #{pid}`
51
      	l =~ /-p (\d+)/
52
      	h[pid] = $1 if $1
53
      }
54
      h
55
    end
56

    
57
    def autoconf
58
      get_pids().length > 0
59
    end
60

    
61
  end
62
end
63

    
64
mpm = Munin::MongrelProcessMemory.new
65

    
66
case ARGV[0]
67
when "config"
68
  puts "graph_title Mongrel Memory"
69
  puts "graph_vlabel RSS"
70
  puts "graph_category memory"
71
  puts "graph_args --base 1024 -l 0"
72
  puts "graph_scale yes"
73
  puts "graph_info Tracks the size of individual mongrel processes"
74
  mpm.get_pids.values.sort.each do |port|
75
    puts "mongrel_#{port}.label mongrel_#{port}"
76
    puts "mongrel_#{port}.info Process memory"
77
    puts "mongrel_#{port}.type GAUGE"
78
    puts "mongrel_#{port}.min 0"
79
  end
80
when "autoconf"
81
  if mpm.autoconf
82
    puts "yes"
83
    exit 0
84
  end
85
  puts "no"
86
  exit 1
87
else
88
  mpm.run
89
end