/
thin_peak_memory
executable file
·103 lines (95 loc) · 2.87 KB
/
thin_peak_memory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env ruby
#############################################################
# thin_peak_memory - A munin plugin for Linux to monitor
# the maximum memory size that each
# individual thin process has reached
# For Linux ONLY !
# DOES NOT WORK on OSX, Solaris or BSD.
# only linux, because this script relies on proc filesystem
#
#############################################################
#
# Based on original code and ideas from:
# thin_process_memory - A munin plugin to monitor memory size of
# each individual thin process
# Copyright (C) 2007 Ben VandenBos and Avvo, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Original Author: Ben VandenBos
# Contributors: Adam Jacob (<adam@hjksolutions.com>)
# Ryan Woodrum
# Matthias Marschall (mm@agileweboperations.com)
#
# Thanks Matthias to help improve this code and made much faster
#
#%# family=auto
#%# capabilities=autoconf
module Munin
class ThinPeakMemory
def run
pids = get_pids()
port_list = Hash.new
pids.sort.each do |pid, port|
hwm = (pid_hwm(pid).to_i)/1024
puts "thin_#{port}.value #{hwm}"
end
end
def pid_hwm(pid)
res = `grep "VmHWM" /proc/#{pid}/status`.split[1]
if res.match("cannot access")
return nil
else
return res
end
end
def get_pids
pids_ports = []
Dir["/var/www/apps/*/shared/pids/thin*.pid"].each do |pid_file|
pid = `cat #{pid_file}`
port = pid_file[/\d\d\d\d/]
pids_ports << [pid,port]
end
pids_ports
end
def autoconf
get_pids().length > 0
end
end
end
mpm = Munin::ThinPeakMemory.new
case ARGV[0]
when "config"
puts "graph_title Thin Peak Memory (High Water Mark)"
puts "graph_vlabel HWM (MB)"
puts "graph_category Thin"
puts "graph_args -l 0"
puts "graph_scale yes"
puts "graph_info Tracks the peak memory of thin processes, aka High Water Mark."
mpm.get_pids.sort.each do |pid,port|
puts "thin_#{port}.label thin_#{port}"
puts "thin_#{port}.info Peak Memory"
puts "thin_#{port}.type GAUGE"
puts "thin_#{port}.min 0"
end
when "autoconf"
if mpm.autoconf
puts "yes"
exit 0
end
puts "no"
exit 1
else
mpm.run
end