Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'optparse'
- @compare = "free"
- opts = OptionParser.new do |o|
- o.banner = "Usage: check_mem [options]"
- o.on( "-w", "--warning WARNING", "Warning on less than n MB free" ) do |w|
- @warning = w.to_i
- end
- o.on( "-c", "--critical CRITICAL", "Critical on less than n MB free" ) do |c|
- @critical = c.to_i
- end
- o.on( "-p", "--plus", "Use free + buffers + cache for comparison" ) do |p|
- @compare = "maybe_free"
- end
- o.on("-h", "--help", "This help" ) do
- puts o
- exit
- end
- end
- begin
- opts.parse!( ARGV )
- free_data=`free`.split("\n")[1].split
- total=free_data[1].to_i
- used=free_data[2].to_i
- shared=free_data[3].to_i
- buffers=free_data[4].to_i
- cached=free_data[5].to_i
- free=total - used
- maybe_free=free + buffers + cached
- if eval("#{@compare} < @critical")
- puts "CRITICAL Mem #{free} M free, #{maybe_free} M free (+buffers and cache)"
- exit 2
- elsif eval("#{@compare} < @warning")
- puts "CRITICAL Mem #{free} M free, #{maybe_free} M free (+buffers and cache)"
- exit 1
- else
- puts "OK Mem #{free} M free, #{maybe_free} M free (+buffers and cache)"
- exit 0
- end
- rescue => exc
- STDERR.puts "E: #{exc.message}"
- STDERR.puts opts.to_s
- exit 3
- end
Add Comment
Please, Sign In to add comment