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