Skip to content

Instantly share code, notes, and snippets.

@bbhoss
Created October 23, 2009 03:24
Show Gist options
  • Save bbhoss/216612 to your computer and use it in GitHub Desktop.
Save bbhoss/216612 to your computer and use it in GitHub Desktop.
require 'bigdecimal'
#Set values to determine output based on how much % of memory is free
CRITICAL=5
WARNING=10
File.open "/proc/meminfo","r" do |line|
@memtotal = BigDecimal.new($1) if line.gets =~ /MemTotal:\s+(\d+)\s+kB/
@memfree = BigDecimal.new($1) if line.gets =~ /MemFree:\s+(\d+)\s+kB/
end
if @memtotal and @memfree
@free_percentage = ((@memfree/@memtotal)*100)
case @free_percentage.to_i
when 0..CRITICAL
print "CRITICAL - Only #{@free_percentage.to_i}% free memory!"
exit 2
when CRITICAL..WARNING
print "WARNING - Only #{@free_percentage.to_i}% free memory!"
exit 1
else
print "OK - #{@free_percentage.to_i}% free memory"
exit 0
end
else
print "UNKNOWN - Cannot get free memory!!!"
exit 3
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment