Created
October 23, 2009 03:24
-
-
Save bbhoss/216612 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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