Class: Heartbeat::Monitor
- Inherits:
-
Object
- Object
- Heartbeat::Monitor
- Defined in:
- lib/tools/heartbeat.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(cycle_length_seconds) ⇒ Monitor
constructor
A new instance of Monitor.
- #measure ⇒ Object
- #sleep ⇒ Object
Constructor Details
#initialize(cycle_length_seconds) ⇒ Monitor
Returns a new instance of Monitor.
67 68 69 70 71 72 73 |
# File 'lib/tools/heartbeat.rb', line 67 def initialize(cycle_length_seconds) @history = History.new(15 * 60 / cycle_length_seconds + 1) @cycle_length_seconds = cycle_length_seconds @count = 0 @started_at = Time.now end |
Instance Method Details
#measure ⇒ Object
75 76 77 78 |
# File 'lib/tools/heartbeat.rb', line 75 def measure @count += 1 take_measurement end |
#sleep ⇒ Object
80 81 82 83 |
# File 'lib/tools/heartbeat.rb', line 80 def sleep sleep_time = (@started_at + @count * @cycle_length_seconds) - Time.now Kernel.sleep sleep_time if sleep_time > 0 end |