Projet

Général

Profil

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

root / plugins / thin / thin_threads @ c39b74e1

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

1
#!/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
# Original author: 
10
#   Frederico de Souza Araujo - fred.the.master@gmail.com
11
#   http://www.frederico-araujo.com
12
#
13
# Usurper:
14
#   Adam Michel - elfurbe@furbism.com
15
#   http://www.furbism.com
16
#
17
# Originally based on:
18
#   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
      instances = get_pids()
45
      instances.each do |instance|
46
        pid, port = instance.split("|")
47
        rss = (get_threads(pid).to_i)/1024
48
        puts "thin_#{port}.value #{rss}"
49
      end
50
    end
51
    
52
    # 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
      res = `grep "Threads" /proc/#{pid}/status`.split[1]
59
      if res.match("cannot access")
60
        return nil
61
      else
62
        return res
63
      end
64
    end
65
        
66
    # fetch all pids that match thin
67
    def get_pids
68
      pids = `pgrep -f 'thin' -l | awk -F " " '{ if (substr( $4, 10, 4)>=1) print $1"|"substr( $4, 10, 4)}'`.split(/\r?\n/)
69
    end
70

    
71
    def autoconf
72
      get_pids().length > 0
73
    end
74
    
75
  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
  puts "graph_category Thin"
85
  puts "graph_args -l 0"
86
  puts "graph_scale yes"
87
  puts "graph_info Tracks how many threads per thin processes"
88
  mpm.get_pids.sort.each do |pid|
89
    puts "thin_#{pid}.label thin_#{pid}"
90
    puts "thin_#{pid}.info Threads per Thin process"
91
    puts "thin_#{pid}.type GAUGE"
92
    puts "thin_#{pid}.min 0"
93
  end
94
when "autoconf"
95
  if mpm.autoconf
96
    puts "yes"
97
    exit 0
98
  end
99
  puts "no"
100
  exit 1
101
else
102
  mpm.run
103
end