Sha256: 462174e83330fbc4441bdb6e81e8ef49736a50e7f8a5e1695c17ada274e052d6
Contents?: true
Size: 1.09 KB
Versions: 2
Compression:
Stored size: 1.09 KB
Contents
require "ffi" require "rapporteur" module Rapporteur module Checks LoadCheckEngine = Class.new(Rails::Engine) class LoadCheck extend FFI::Library ffi_lib FFI::Library::LIBC attach_function :getloadavg, [:pointer, :int], :int attach_function :strerror, [:int], :string private_class_method :getloadavg, :strerror DEFAULT_TOLERANCE = 8.0 def initialize(tolerance=DEFAULT_TOLERANCE) @tolerance = tolerance end def call(checker) loadavg = self.class.current_load if loadavg > @tolerance checker.add_error(:load, :excessive, tolerance: @tolerance, value: loadavg) checker.halt! else checker.add_message(:load, loadavg) end end def self.call(checker) new.call(checker) end 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 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rapporteur-load_check-2.1.0 | lib/rapporteur/load_check.rb |
rapporteur-load_check-2.0.0 | lib/rapporteur/load_check.rb |