Projet

Général

Profil

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

root / plugins / thin / thin_memory @ 17f78427

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

1
#!/usr/bin/env ruby
2
# thin_memory - A munin plugin for Linux to monitor memory size of each individual thin process
3
#
4
# For Linux ONLY !
5
# DOES NOT WORK on OSX, Solaris or BSD.
6
# only linux, because this script relies on proc filesystem
7
#
8
# Original author:
9
#   Frederico de Souza Araujo - fred.the.master@gmail.com
10
#   http://www.frederico-araujo.com
11
#
12
# Usurper:
13
#   Adam Michel - elfurbe@furbism.com
14
#   http://www.furbism.com
15
#
16
# Originally based on:
17
#   thin_process_memory -
18
#       A munin plugin to monitor memory size of
19
#       each individual thin process
20
#   by Ben VandenBos and Avvo, Inc.
21
#
22
# This program is free software; you can redistribute it and/or modify
23
# it under the terms of the GNU General Public License version 2
24
# as published by the Free Software Foundation.
25
#
26
# This program is distributed in the hope that it will be useful,
27
# but WITHOUT ANY WARRANTY; without even the implied warranty of
28
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
# GNU General Public License for more details.
30
#
31
# You should have received a copy of the GNU General Public License along
32
# with this program; if not, write to the Free Software Foundation, Inc.,
33
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34
#
35
#
36
#%# family=auto
37
#%# capabilities=autoconf
38

    
39
module Munin
40
  class ThinProcessMemory
41

    
42
    # run main method
43
    def run
44
      instances = get_pids()
45
      instances.each do |instance|
46
        pid, port = instance.split("|")
47
        rss = (pid_rss(pid).to_i)/1024
48
        puts "thin_#{port}.value #{rss}"
49
      end
50
    end
51

    
52
    # only get the memory for each pid
53
    def pid_rss(pid)
54
      res = `grep "VmRSS" /proc/#{pid}/status`.split[1]
55
      if res.match("cannot access")
56
        return nil
57
      else
58
        return res
59
      end
60
    end
61

    
62
    # fetch all pids that match thin
63
    def get_pids
64
      pids = `pgrep -f 'thin' -l | awk -F " " '{ if (substr( $4, 10, 4)>=1) print $1"|"substr( $4, 10, 4)}' | sort -t'|' -nk 2`.split(/\r?\n/)
65
    end
66

    
67
    def autoconf
68
      get_pids().length > 0
69
    end
70

    
71
  end
72
end
73

    
74
mpm = Munin::ThinProcessMemory.new
75

    
76
case ARGV[0]
77
when "config"
78
  puts "graph_title Thin Memory"
79
  puts "graph_vlabel RSS"
80
  puts "graph_category webserver"
81
  puts "graph_args --base 1024 -l 0"
82
  puts "graph_scale yes"
83
  puts "graph_info Tracks the size of individual thin processes"
84
  mpm.get_pids.each do |instance|
85
    pid, port = instance.split("|")
86
    puts "thin_#{port}.label thin_#{port}"
87
    puts "thin_#{port}.info Process memory"
88
    puts "thin_#{port}.type GAUGE"
89
    puts "thin_#{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