public
Last active

Nagios Passenger memory check

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#!/usr/local/bin/ruby
 
require 'rubygems'
gem 'passenger'
require 'phusion_passenger'
require 'phusion_passenger/platform_info'
require 'phusion_passenger/admin_tools/memory_stats'
require 'optparse'
 
include PhusionPassenger
 
def pluralize(str, count)
if count > 1
"#{str}s"
else
str
end
end
 
def singularize(str, count)
if count > 1
str
else
"#{str}s"
end
end
 
options = {:warning_threshold => 80, :critical_threshold => 100}
OptionParser.new do |opts|
opts.banner = "Usage: check_passenger [options]"
opts.on("-w N", "--warning", "Warning threshold in MB") do |w|
options[:warning_threshold] = w.to_i
end
opts.on("-c N", "--critical", "Critical threshold in MB") do |c|
options[:critical_threshold] = c.to_i
end
end.parse!
 
procs = AdminTools::MemoryStats.new.passenger_processes
 
msg, exit_code = if procs.find { |p| p.rss > options[:critical_threshold]*1000 }
count = procs.count {|p|p.rss > options[:critical_threshold]*1000 }
["CRITICAL - #{count} #{pluralize('instance', count)} #{singularize('exceed', count)} #{options[:critical_threshold]} MB", 2]
elsif procs.find {|p| p.rss > options[:warning_threshold]*1000 }
count = procs.count {|p|p.rss > options[:warning_threshold]*1000 }
["WARNING - #{count} #{pluralize('instance', count)} #{singularize('exceed', count)} #{options[:warning_threshold]} MB", 1]
else
["OK - No processes exceed #{options[:warning_threshold]} MB", 0]
end
 
puts "PASSENGER #{msg}"
exit exit_code

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.