Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / thin / thin_threads @ f9000cdc

Historique | Voir | Annoter | Télécharger (2,67 ko)

1 6de0bb7e Frederico de Souza Araujo
#!/usr/bin/env ruby
2
# thin_threads - 
3
#   A munin plugin for Linux to monitor how many threads per thin process
4
# 
5
# For Linux ONLY !
6
# DOES NOT WORK on OSX, Solaris or BSD.
7
# only linux, because this script relies on proc filesystem
8
# 
9 afe66001 ElFurbe
# 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 6de0bb7e Frederico de Souza Araujo
#   thin_process_memory - 
19
#       A munin plugin to monitor memory size of 
20
#       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
# it under the terms of the GNU General Public License version 2 
25
# as published by the Free Software Foundation.
26
# 
27
# 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
# 
32
# 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
    
43
    def run
44
      pids = get_pids()
45 afe66001 ElFurbe
      pids.sort.each do |pid|
46 6de0bb7e Frederico de Souza Araujo
        res = (get_threads(pid).to_i)
47 afe66001 ElFurbe
        puts "thin_#{pid}.value #{res}"
48 6de0bb7e Frederico de Souza Araujo
      end
49
    end
50
    
51
    # only get threads count for each pid
52
    # Using Proc filesystem
53
    # ONLY LINUX! because relies on proc filesystem
54
    # TODO: make this work on OSX and Solaris,
55
    #        so the whole unix gang is happy ;)
56
    def get_threads(pid)
57
      res = `grep "Threads" /proc/#{pid}/status`.split[1]
58
      if res.match("cannot access")
59
        return nil
60
      else
61
        return res
62
      end
63
    end
64
    
65
    
66
    # Get pis using lsof (list open files) 
67
    #   look for listening tcp applications 
68
    #   that match the name thin
69
    def get_pids
70
      pids = `pgrep thin`.split
71
    end
72
73
    def autoconf
74
      get_pids().length > 0
75
    end
76
    
77
  end
78
end
79
80
mpm = Munin::ThinThreads.new
81
82
case ARGV[0]
83
when "config"
84
  puts "graph_title Thin Threads"
85
  puts "graph_vlabel Threads"
86
  puts "graph_category Thin"
87
  puts "graph_args -l 0"
88
  puts "graph_scale yes"
89
  puts "graph_info Tracks how many threads per thin processes"
90 afe66001 ElFurbe
  mpm.get_pids.sort.each do |pid|
91
    puts "thin_#{pid}.label thin_#{pid}"
92
    puts "thin_#{pid}.info Threads per Thin process"
93
    puts "thin_#{pid}.type GAUGE"
94
    puts "thin_#{pid}.min 0"
95 6de0bb7e Frederico de Souza Araujo
  end
96
when "autoconf"
97
  if mpm.autoconf
98
    puts "yes"
99
    exit 0
100
  end
101
  puts "no"
102
  exit 1
103
else
104
  mpm.run
105
end