root / plugins / thin / thin_threads @ b0b39b01
Historique | Voir | Annoter | Télécharger (2,73 ko)
| 1 |
#!/usr/bin/env ruby |
|---|---|
| 2 |
|
| 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 |
#%# family=auto |
| 41 |
#%# capabilities=autoconf |
| 42 |
|
| 43 |
=end |
| 44 |
|
| 45 |
|
| 46 |
module Munin |
| 47 |
class ThinThreads |
| 48 |
def run |
| 49 |
instances = get_pids() |
| 50 |
instances.each do |instance| |
| 51 |
pid, port = instance.split("|")
|
| 52 |
rss = (get_threads(pid).to_i) |
| 53 |
puts "thin_#{port}.value #{rss}"
|
| 54 |
end |
| 55 |
end |
| 56 |
|
| 57 |
# 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 |
res = `grep "Threads" /proc/#{pid}/status | cut -d ":" -f2`.gsub(/\s+/, "")
|
| 64 |
if res.match("cannot access")
|
| 65 |
return nil |
| 66 |
else |
| 67 |
return res |
| 68 |
end |
| 69 |
end |
| 70 |
|
| 71 |
# fetch all pids that match thin |
| 72 |
def get_pids |
| 73 |
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 |
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 |
puts "graph_category webserver" |
| 89 |
puts "graph_args -l 0" |
| 90 |
puts "graph_scale yes" |
| 91 |
puts "graph_info Tracks how many threads per thin processes" |
| 92 |
mpm.get_pids.each do |instance| |
| 93 |
pid, port = instance.split("|")
|
| 94 |
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 |
end |
| 99 |
when "autoconf" |
| 100 |
if mpm.autoconf |
| 101 |
puts "yes" |
| 102 |
exit 0 |
| 103 |
end |
| 104 |
puts "no" |
| 105 |
exit 0 |
| 106 |
else |
| 107 |
mpm.run |
| 108 |
end |
