class NSCA::PerformanceData::Base
Attributes
crit[R]
label[R]
max[R]
min[R]
unit[R]
warn[R]
value[R]
Public Class Methods
clone( opts = nil)
click to toggle source
# File lib/nsca/check.rb, line 42 def clone( opts = nil) ::Class.new( self).init opts ? to_h.merge( opts) : to_h end
init(*args)
click to toggle source
# File lib/nsca/check.rb, line 12 def init *args a, o = args, args.last.is_a?( Hash) ? args.pop : {} @label, @unit = a[0]||o[:label], a[1]||o[:unit] @warn, @crit = a[2]||o[:warn], a[3]||o[:crit] @min, @max = a[4]||o[:min], a[5]||o[:max] raise ArgumentError, "Label expected" unless @label @label = @label.to_s self end
measure(&block)
click to toggle source
# File lib/nsca/check.rb, line 22 def measure &block f = case unit.to_s.to_sym when :s then 1 when :ms then 1000 else raise TimeUnitExpected, "Unit must be seconds (s) or miliseconds (ms) not (#{unit})" end exception = ::Class.new Timeout::Error timeout = max m = realtime do begin timeout timeout, exception, &block rescue exception end end new f * m end
new( value)
click to toggle source
# File lib/nsca/check.rb, line 46 def initialize( value) @value = value end
to_a()
click to toggle source
# File lib/nsca/check.rb, line 41 def to_a() [label, unit, warn, crit, min, max] end
to_h()
click to toggle source
# File lib/nsca/check.rb, line 40 def to_h() {label: @label, unit: @unit, warn: @warn, crit: @crit, min: @min, max: @max } end
to_sym()
click to toggle source
# File lib/nsca/check.rb, line 39 def to_sym() label.to_sym end
Public Instance Methods
crit()
click to toggle source
# File lib/nsca/check.rb, line 50 def crit() self.class.crit end
label()
click to toggle source
# File lib/nsca/check.rb, line 47 def label() self.class.label end
max()
click to toggle source
# File lib/nsca/check.rb, line 52 def max() self.class.max end
min()
click to toggle source
# File lib/nsca/check.rb, line 51 def min() self.class.min end
return_code()
click to toggle source
# File lib/nsca/check.rb, line 61 def return_code if @value.nil? then 3 elsif crit <= @value then 2 elsif warn <= @value then 1 else 0 end end
to_a()
click to toggle source
# File lib/nsca/check.rb, line 53 def to_a() [label, value, unit, warn, crit, min, max] end
to_h()
click to toggle source
# File lib/nsca/check.rb, line 57 def to_h {label: @label, value: @value, unit: @unit, warn: @warn, crit: @crit, min: @min, max: @max} end
to_s()
click to toggle source
# File lib/nsca/check.rb, line 54 def to_s() "'#{label.gsub /[\n'\|]/, ''}'=#{value}#{unit},#{warn},#{crit},#{min},#{max}" end
to_sym()
click to toggle source
# File lib/nsca/check.rb, line 55 def to_sym() self.class.to_sym end
unit()
click to toggle source
# File lib/nsca/check.rb, line 48 def unit() self.class.unit end
warn()
click to toggle source
# File lib/nsca/check.rb, line 49 def warn() self.class.warn end