root / plugins / thin / thins_peak_memory @ c3660c2a
Historique | Voir | Annoter | Télécharger (2,79 ko)
| 1 | fb361e1b | Frederico de Souza Araujo | #!/usr/bin/env ruby |
|---|---|---|---|
| 2 | # thin_peak_memory - |
||
| 3 | # A munin plugin for Linux to monitor the maximum memory size |
||
| 4 | # that an each individual thin process has reached |
||
| 5 | # |
||
| 6 | # For Linux ONLY ! |
||
| 7 | # DOES NOT WORK on OSX, Solaris or BSD. |
||
| 8 | # only linux, because this script relies on proc filesystem |
||
| 9 | # |
||
| 10 | # Author: |
||
| 11 | # Frederico de Souza Araujo - fred.the.master@gmail.com |
||
| 12 | # http://www.frederico-araujo.com |
||
| 13 | # |
||
| 14 | # Based on: |
||
| 15 | # thin_process_memory - |
||
| 16 | # A munin plugin to monitor memory size of |
||
| 17 | # each individual thin process |
||
| 18 | # by Ben VandenBos and Avvo, Inc. |
||
| 19 | # |
||
| 20 | # This program is free software; you can redistribute it and/or modify |
||
| 21 | # it under the terms of the GNU General Public License version 2 |
||
| 22 | # as published by the Free Software Foundation. |
||
| 23 | # |
||
| 24 | # This program is distributed in the hope that it will be useful, |
||
| 25 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 26 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 27 | # GNU General Public License for more details. |
||
| 28 | # |
||
| 29 | # You should have received a copy of the GNU General Public License along |
||
| 30 | # with this program; if not, write to the Free Software Foundation, Inc., |
||
| 31 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
||
| 32 | # |
||
| 33 | # |
||
| 34 | #%# family=auto |
||
| 35 | #%# capabilities=autoconf |
||
| 36 | |||
| 37 | module Munin |
||
| 38 | class ThinPeakMemory |
||
| 39 | |||
| 40 | def run |
||
| 41 | c39b74e1 | Thomas VIAL | instances = get_pids() |
| 42 | instances.each do |instance| |
||
| 43 | pid, port = instance.split("|")
|
||
| 44 | fb361e1b | Frederico de Souza Araujo | hwm = (pid_hwm(pid).to_i)/1024 |
| 45 | puts "thin_#{port}.value #{hwm}"
|
||
| 46 | end |
||
| 47 | end |
||
| 48 | |||
| 49 | # only get VmHWM count for each pid |
||
| 50 | # (Virtual Memory High Water Mark) |
||
| 51 | # Using Proc filesystem |
||
| 52 | # ONLY LINUX! because relies on proc filesystem |
||
| 53 | # TODO: make this work on OSX and Solaris, |
||
| 54 | # so the whole unix gang is happy ;) |
||
| 55 | def pid_hwm(pid) |
||
| 56 | res = `grep "VmHWM" /proc/#{pid}/status`.split[1]
|
||
| 57 | if res.match("cannot access")
|
||
| 58 | return nil |
||
| 59 | else |
||
| 60 | return res |
||
| 61 | end |
||
| 62 | end |
||
| 63 | |||
| 64 | c39b74e1 | Thomas VIAL | # fetch all pids that match thin |
| 65 | fb361e1b | Frederico de Souza Araujo | def get_pids |
| 66 | 08c3a67e | Thomas Vial | 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/)
|
| 67 | fb361e1b | Frederico de Souza Araujo | end |
| 68 | |||
| 69 | def autoconf |
||
| 70 | get_pids().length > 0 |
||
| 71 | end |
||
| 72 | |||
| 73 | end |
||
| 74 | end |
||
| 75 | |||
| 76 | mpm = Munin::ThinPeakMemory.new |
||
| 77 | |||
| 78 | case ARGV[0] |
||
| 79 | when "config" |
||
| 80 | puts "graph_title Thin Peak Memory (High Water Mark)" |
||
| 81 | puts "graph_vlabel HWM" |
||
| 82 | puts "graph_category Thin" |
||
| 83 | puts "graph_args -l 0" |
||
| 84 | puts "graph_scale yes" |
||
| 85 | puts "graph_info Tracks the peak memory of thin processes, aka High Water Mark." |
||
| 86 | 82911254 | Thomas Vial | mpm.get_pids.each do |instance| |
| 87 | f847a3a4 | Thomas VIAL | pid, port = instance.split("|")
|
| 88 | fb361e1b | Frederico de Souza Araujo | puts "thin_#{port}.label thin_#{port}"
|
| 89 | puts "thin_#{port}.info Peak Memory"
|
||
| 90 | puts "thin_#{port}.type GAUGE"
|
||
| 91 | puts "thin_#{port}.min 0"
|
||
| 92 | end |
||
| 93 | when "autoconf" |
||
| 94 | if mpm.autoconf |
||
| 95 | puts "yes" |
||
| 96 | exit 0 |
||
| 97 | end |
||
| 98 | puts "no" |
||
| 99 | exit 1 |
||
| 100 | else |
||
| 101 | mpm.run |
||
| 102 | end |
