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