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