#!/usr/bin/ruby # loadcheck.rb # This app pulls the system load via the 'uptime' command and checks the # first value against the defined threshold. If the load is greater than the # threshold, an email is dispatched with the current load values. # Threshold value TH = 3.0 # Regexp pattern for matching the load value for the last 15 minutes pat = "(\\d+\\.\\d+), (\\d+\\.\\d+), (\\d+\\.\\d+)?" # %x will execute the uptime command and return the output to uptime uptime = %x[uptime] # Declare a new regexp and attempt to match it against the output of uptime re = Regexp.new(pat) load1 = re.match(uptime)[1] load5 = re.match(uptime)[2] load15 = re.match(uptime)[3] puts "Last minute: #{load1}" puts "Last five minutes: #{load5}" puts "Last fifteen minutes: #{load15}" #if load1.to_f <= (TH - 0.01) # puts "Load below threshold!\n" #else # puts "Load at or above threshold!\n" #end