Class: Rapporteur::Checks::LoadCheck
- Inherits:
-
Object
- Object
- Rapporteur::Checks::LoadCheck
- Extended by:
- FFI::Library
- Defined in:
- lib/rapporteur/load_check.rb
Constant Summary collapse
- DEFAULT_TOLERANCE =
8.0
Class Method Summary collapse
Instance Method Summary collapse
- #call(checker) ⇒ Object
-
#initialize(tolerance = DEFAULT_TOLERANCE) ⇒ LoadCheck
constructor
A new instance of LoadCheck.
Constructor Details
#initialize(tolerance = DEFAULT_TOLERANCE) ⇒ LoadCheck
Returns a new instance of LoadCheck.
20 21 22 |
# File 'lib/rapporteur/load_check.rb', line 20 def initialize(tolerance=DEFAULT_TOLERANCE) @tolerance = tolerance end |
Class Method Details
.call(checker) ⇒ Object
35 36 37 |
# File 'lib/rapporteur/load_check.rb', line 35 def self.call(checker) new.call(checker) end |
.current_load ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/rapporteur/load_check.rb', line 39 def self.current_load loadavg = FFI::MemoryPointer.new(:double, 1) if getloadavg(loadavg, 1) == -1 raise SystemCallError, "getloadavg() - #{strerror(FFI.errno)}" end loadavg.read_double end |
Instance Method Details
#call(checker) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rapporteur/load_check.rb', line 24 def call(checker) loadavg = self.class.current_load if loadavg > @tolerance checker.add_error(:load, :excessive, :tolerance => @tolerance, :value => loadavg) checker.halt! else checker.(:load, loadavg) end end |