3 if RUBY_PLATFORM =~
/(:?mswin|mingw)/ then abort("Inspector is only for Unix") end
6 :pid_path => File
.expand_path(RAILS_ROOT
+ '/tmp/pids'),
7 :pattern => "dispatch.*.pid",
8 :ps => "ps -o pid,state,user,start,time,pcpu,vsz,majflt,command -p %s"
12 def self.inspect(pid_path
, pattern
)
13 new(pid_path
, pattern
).inspect
16 def initialize(pid_path
, pattern
)
17 @pid_path, @pattern = pid_path
, pattern
21 header
= `#{OPTIONS[:ps] % 1}`.split("\n")[0] + "\n"
22 lines
= pids
.collect
{ |pid
| `#{OPTIONS[:ps] % pid}`.split("\n")[1] }
24 puts(header
+ lines
.join("\n"))
29 pid_files
.collect
do |pid_file
|
30 File
.read(pid_file
).to_i
35 Dir
.glob(@pid_path + "/" + @pattern)
40 ARGV.options
do |opts
|
41 opts
.banner
= "Usage: inspector [options]"
47 Displays system information about Rails dispatchers (or other processes that use pid files) through
51 inspector # default ps on all tmp/pids/dispatch.*.pid files
52 inspector -s 'ps -o user,start,majflt,pcpu,vsz -p %s' # custom ps, %s is where the pid is interleaved
57 opts
.on("-s", "--ps=command", "default: #{OPTIONS[:ps]}", String
) { |v
| OPTIONS
[:ps] = v
}
58 opts
.on("-p", "--pidpath=path", "default: #{OPTIONS[:pid_path]}", String
) { |v
| OPTIONS
[:pid_path] = v
}
59 opts
.on("-r", "--pattern=pattern", "default: #{OPTIONS[:pattern]}", String
) { |v
| OPTIONS
[:pattern] = v
}
63 opts
.on("-h", "--help", "Show this help message.") { puts opts
; exit
}
68 Inspector
.inspect(OPTIONS
[:pid_path], OPTIONS
[:pattern])