Permalink
Newer
Older
100755 47 lines (37 sloc) 1.2 KB
1
#!/usr/bin/env ruby
2
3
require 'optparse'
4
5
OK_STATE=0
6
WARNING_STATE=1
7
CRITICAL_STATE=2
8
UNKNOWN_STATE=3
9
10
options = {}
11
optparse = OptionParser.new do |opts|
12
opts.banner = "Usage: #{$0} [OPTIONS]"
13
14
opts.on('-w', '--warn WORKERS', 'Warn if number of workers is over WORKERS') do |val|
15
options[:warn_wks] = val.to_i
16
end
17
18
opts.on('-c', '--crit WORKERS', 'Critical if number of workers is under WORKERS') do |val|
19
options[:crit_wks] = val.to_i
20
end
21
22
opts.on('-h', '--help', 'Display this screen') do
23
puts opts
24
exit
25
end
26
end
27
28
optparse.parse!
29
30
unless options[:crit_wks] && options[:warn_wks]
31
puts optparse.help
32
exit
33
end
34
35
current_workers =`ps -ef | grep delayed | grep -v grep`.split("\n").map { |x| x.split("\s")[10] }
Jun 28, 2012
36
#workers = `ps -ef | grep delayed | grep -v grep`.collect { |job| job =~ / -i (\d{1,2})/; $1; }
37
38
if current_workers.count > options[:warn_wks]
39
puts "WARNING - There are too many DJ workers running : #{current_workers.count}"
40
exit WARNING_STATE
41
elsif current_workers.count < options[:crit_wks]
42
puts "CRITICAL - Missing #{options[:crit_wks] - current_workers.count} DJ workers !"
43
exit CRITICAL_STATE
44
else
45
puts "OK - #{current_workers.count} DJ workers currently running."