2009-06-18 10:11:07 +02:00
|
|
|
#!/usr/bin/env ruby
|
2018-08-02 02:03:42 +02:00
|
|
|
# thin_threads -
|
2009-06-18 10:11:07 +02:00
|
|
|
# A munin plugin for Linux to monitor how many threads per thin process
|
2018-08-02 02:03:42 +02:00
|
|
|
#
|
2009-06-18 10:11:07 +02:00
|
|
|
# For Linux ONLY !
|
|
|
|
# DOES NOT WORK on OSX, Solaris or BSD.
|
|
|
|
# only linux, because this script relies on proc filesystem
|
2018-08-02 02:03:42 +02:00
|
|
|
#
|
|
|
|
# Original author:
|
2009-06-18 10:11:07 +02:00
|
|
|
# Frederico de Souza Araujo - fred.the.master@gmail.com
|
|
|
|
# http://www.frederico-araujo.com
|
|
|
|
#
|
2011-08-17 05:34:13 +02:00
|
|
|
# Usurper:
|
|
|
|
# Adam Michel - elfurbe@furbism.com
|
|
|
|
# http://www.furbism.com
|
|
|
|
#
|
|
|
|
# Originally based on:
|
2018-08-02 02:03:42 +02:00
|
|
|
# thin_process_memory -
|
|
|
|
# A munin plugin to monitor memory size of
|
2009-06-18 10:11:07 +02:00
|
|
|
# each individual thin process
|
|
|
|
# by Ben VandenBos and Avvo, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
2018-08-02 02:03:42 +02:00
|
|
|
# it under the terms of the GNU General Public License version 2
|
2009-06-18 10:11:07 +02:00
|
|
|
# as published by the Free Software Foundation.
|
2018-08-02 02:03:42 +02:00
|
|
|
#
|
2009-06-18 10:11:07 +02:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2018-08-02 02:03:42 +02:00
|
|
|
#
|
2009-06-18 10:11:07 +02:00
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
module Munin
|
|
|
|
class ThinThreads
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2009-06-18 10:11:07 +02:00
|
|
|
def run
|
2013-02-15 10:00:06 +01:00
|
|
|
instances = get_pids()
|
|
|
|
instances.each do |instance|
|
|
|
|
pid, port = instance.split("|")
|
2013-04-04 10:00:04 +02:00
|
|
|
rss = (get_threads(pid).to_i)
|
2013-02-15 10:00:06 +01:00
|
|
|
puts "thin_#{port}.value #{rss}"
|
2009-06-18 10:11:07 +02:00
|
|
|
end
|
|
|
|
end
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2009-06-18 10:11:07 +02:00
|
|
|
# only get threads count for each pid
|
|
|
|
# Using Proc filesystem
|
|
|
|
# ONLY LINUX! because relies on proc filesystem
|
|
|
|
# TODO: make this work on OSX and Solaris,
|
|
|
|
# so the whole unix gang is happy ;)
|
|
|
|
def get_threads(pid)
|
2013-04-04 10:00:04 +02:00
|
|
|
res = `grep "Threads" /proc/#{pid}/status | cut -d ":" -f2`.gsub(/\s+/, "")
|
2009-06-18 10:11:07 +02:00
|
|
|
if res.match("cannot access")
|
|
|
|
return nil
|
|
|
|
else
|
|
|
|
return res
|
|
|
|
end
|
|
|
|
end
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2013-02-15 10:00:06 +01:00
|
|
|
# fetch all pids that match thin
|
2009-06-18 10:11:07 +02:00
|
|
|
def get_pids
|
2013-06-08 18:07:26 +02:00
|
|
|
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/)
|
2009-06-18 10:11:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def autoconf
|
|
|
|
get_pids().length > 0
|
|
|
|
end
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2009-06-18 10:11:07 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
mpm = Munin::ThinThreads.new
|
|
|
|
|
|
|
|
case ARGV[0]
|
|
|
|
when "config"
|
|
|
|
puts "graph_title Thin Threads"
|
|
|
|
puts "graph_vlabel Threads"
|
2017-02-23 20:45:01 +01:00
|
|
|
puts "graph_category webserver"
|
2009-06-18 10:11:07 +02:00
|
|
|
puts "graph_args -l 0"
|
|
|
|
puts "graph_scale yes"
|
|
|
|
puts "graph_info Tracks how many threads per thin processes"
|
2013-06-12 16:59:48 +02:00
|
|
|
mpm.get_pids.each do |instance|
|
2018-08-02 02:03:42 +02:00
|
|
|
pid, port = instance.split("|")
|
2013-02-15 10:55:42 +01:00
|
|
|
puts "thin_#{port}.label thin_#{port}"
|
|
|
|
puts "thin_#{port}.info Threads per Thin process"
|
|
|
|
puts "thin_#{port}.type GAUGE"
|
|
|
|
puts "thin_#{port}.min 0"
|
2009-06-18 10:11:07 +02:00
|
|
|
end
|
|
|
|
when "autoconf"
|
|
|
|
if mpm.autoconf
|
|
|
|
puts "yes"
|
|
|
|
exit 0
|
|
|
|
end
|
|
|
|
puts "no"
|
2018-09-16 04:01:57 +02:00
|
|
|
exit 0
|
2009-06-18 10:11:07 +02:00
|
|
|
else
|
|
|
|
mpm.run
|
|
|
|
end
|