Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 43 lines (33 sloc) 1.43 KB
#!/usr/bin/env ruby
require 'yaml'
if ARGV.count != 0
puts "Usage: #{$0}"
exit 3
end
OK_STATE = 0
WARNING_STATE = 1
CRITICAL_STATE = 2
UNKNOWN_STATE = 3
RAILS_ROOT = '/home/deploy/www/taskrabbit/current'
env = `su - deploy -c 'source /home/deploy/.ssh/environment ; . /home/deploy/.ssh/environment ; echo $RAILS_ENV'`.strip
dj = YAML.load_file("#{RAILS_ROOT}/config/delayed_jobs.yml")[env]['servers'][`hostname`.strip]
wks = dj.collect { |wkr| wkr =~ /-i (\d{1,2})/; $1.to_s }
min_prio = dj.collect { |min| min =~ /--min-priority (\d{1,})/; $1 }
max_prio = dj.collect { |max| max =~ /--max-priority (\d{1,})/; $1 }
#puts "Workers expected : #{wks.join(" ")}"
#puts "Minimum priority : #{min_prio.join(" ")}"
#puts "Maximum priority : #{max_prio.join(" ")}"
current_workers =`ps awx | grep delayed | grep -v grep | grep -v tail`.split("\n").map { |x| x.split("\s")[7].to_s }
#puts "Workers : #{current_workers.join(" ")}"
#puts wks - current_workers
#workers = `ps -ef | grep delayed | grep -v grep`.collect { |job| job =~ / -i (\d{1,2})/; $1; }
if current_workers.count > wks.count
puts "WARNING - There are too many DJ workers running : #{current_workers.count}"
exit WARNING_STATE
elsif current_workers.count < wks.count
puts "CRITICAL - Missing #{wks.count - current_workers.count} DJ workers ! Culprit : #{wks - current_workers}"
exit CRITICAL_STATE
else
puts "OK - #{current_workers.count} DJ workers currently running"
exit OK_STATE
end