Module: CloudFlock::App::Watchdogs
Overview
Public: The Watchdogs module provides commonly used watchdogs.
Instance Method Summary collapse
-
#set_alarm_system_load(watchdog, thread) ⇒ Object
Public: Set up a default alert for if the system load is >10, killing a given thread if it reaches that threshhold.
-
#set_alarm_used_space(watchdog, thread) ⇒ Object
Public: Set up a default alert for if free space on the host falls below 5%, killing a given thread if it reaches that threshhold.
-
#set_alarm_utilized_memory(watchdog, thread) ⇒ Object
Public: Set up a default alert for when swap used is > 25%, killing a given thread if it reaches that threshhold.
-
#system_load(ssh, name) ⇒ Object
Public: Create a Watchdog which monitors the system load average on a given host.
-
#used_space(ssh, name) ⇒ Object
Public: Create a Watchdog which monitors the used disk space on a given host.
-
#utilized_memory(ssh, name) ⇒ Object
Public: Create a Watchdog which monitors the memory in use on a given host.
Instance Method Details
#set_alarm_system_load(watchdog, thread) ⇒ Object
Public: Set up a default alert for if the system load is >10, killing a given thread if it reaches that threshhold.
watchdog - Watchdog to which the alarm should be added. thread - Thread to kill if the alarm fires.
Returns nothing.
72 73 74 75 |
# File 'lib/cloudflock/app/common/watchdogs.rb', line 72 def set_alarm_system_load(watchdog, thread) watchdog.create_alarm('load_too_high') { |waitq| waitq > 10 } watchdog.on_alarm('load_too_high') { |waitq| thread.kill } end |
#set_alarm_used_space(watchdog, thread) ⇒ Object
Public: Set up a default alert for if free space on the host falls below 5%, killing a given thread if it reaches that threshhold.
watchdog - Watchdog to which the alarm should be added. thread - Thread to kill if the alarm fires.
Returns nothing.
60 61 62 63 |
# File 'lib/cloudflock/app/common/watchdogs.rb', line 60 def set_alarm_used_space(watchdog, thread) watchdog.create_alarm('out_of_space') { |space| space > 0.95 } watchdog.on_alarm('out_of_space') { |space| thread.kill } end |
#set_alarm_utilized_memory(watchdog, thread) ⇒ Object
Public: Set up a default alert for when swap used is > 25%, killing a given thread if it reaches that threshhold.
watchdog - Watchdog to which the alarm should be added. thread - Thread to kill if the alarm fires.
Returns nothing.
84 85 86 87 |
# File 'lib/cloudflock/app/common/watchdogs.rb', line 84 def set_alarm_utilized_memory(watchdog, thread) watchdog.create_alarm('swapping') { |swap| swap > 0.25 } watchdog.on_alarm('swapping') { |swap| thread.kill } end |
#system_load(ssh, name) ⇒ Object
Public: Create a Watchdog which monitors the system load average on a given host.
ssh - SSH session which the Watchdog should monitor. name - String describing the Watchdog.
Returns a Watchdog.
32 33 34 35 36 |
# File 'lib/cloudflock/app/common/watchdogs.rb', line 32 def system_load(ssh, name) CloudFlock::Remote::SSH::Watchdog.new(name, ssh, 'uptime', 15) do |uptime| uptime.split(/\s+/)[-3].to_f end end |
#used_space(ssh, name) ⇒ Object
Public: Create a Watchdog which monitors the used disk space on a given host.
ssh - SSH session which the Watchdog should monitor. name - String describing the Watchdog.
Returns a Watchdog.
16 17 18 19 20 21 22 23 |
# File 'lib/cloudflock/app/common/watchdogs.rb', line 16 def used_space(ssh, name) CloudFlock::Remote::SSH::Watchdog.new(name, ssh, 'df', 60) do |df| lines = df.lines.select { |line| /^[^ ]*(?:\s+\d+){2,}/.match line } total = lines.map { |line| line.split(/\s+/)[1].to_i }.reduce(&:+) used = lines.map { |line| line.split(/\s+/)[2].to_i }.reduce(&:+) used.to_f / total end end |
#utilized_memory(ssh, name) ⇒ Object
Public: Create a Watchdog which monitors the memory in use on a given host.
ssh - SSH session which the Watchdog should monitor. name - String describing the Watchdog.
Returns a Watchdog.
45 46 47 48 49 50 51 |
# File 'lib/cloudflock/app/common/watchdogs.rb', line 45 def utilized_memory(ssh, name) CloudFlock::Remote::SSH::Watchdog.new(name, ssh, 'free', 15) do |free| lines = free.lines.select { |line| /Swap/.match line } total,used = lines.empty? ? [0,0] : lines.map(&:to_f)[1..2] total > 0 ? free / total : 0.0 end end |