All pastes #587126 Raw Edit

Miscellany

public ruby v1 · immutable
#587126 ·published 2007-06-24 08:56 UTC
rendered paste body
#!/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 valueTH = 3.0# Regexp pattern for matching the load value for the last 15 minutespat = "(\\d+\\.\\d+), (\\d+\\.\\d+), (\\d+\\.\\d+)?"# %x will execute the uptime command and return the output to uptimeuptime = %x[uptime]# Declare a new regexp and attempt to match it against the output of uptimere = 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