Class: NSCA::PerformanceData::Base
- Inherits:
-
Object
- Object
- NSCA::PerformanceData::Base
- Extended by:
- Benchmark, Timeout
- Defined in:
- lib/nsca/check.rb
Class Attribute Summary collapse
-
.crit ⇒ Object
readonly
Returns the value of attribute crit.
-
.label ⇒ Object
readonly
Returns the value of attribute label.
-
.max ⇒ Object
readonly
Returns the value of attribute max.
-
.min ⇒ Object
readonly
Returns the value of attribute min.
-
.unit ⇒ Object
readonly
Returns the value of attribute unit.
-
.warn ⇒ Object
readonly
Returns the value of attribute warn.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
- .clone(opts = nil) ⇒ Object
- .init(*args) ⇒ Object
- .measure(&block) ⇒ Object
- .to_a ⇒ Object
- .to_h ⇒ Object
- .to_sym ⇒ Object
Instance Method Summary collapse
- #crit ⇒ Object
-
#initialize(value) ⇒ Base
constructor
A new instance of Base.
- #label ⇒ Object
- #max ⇒ Object
- #min ⇒ Object
- #return_code ⇒ Object
- #to_a ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
- #to_sym ⇒ Object
- #unit ⇒ Object
- #warn ⇒ Object
Constructor Details
#initialize(value) ⇒ Base
Returns a new instance of Base.
46 |
# File 'lib/nsca/check.rb', line 46 def initialize( value) @value = value end |
Class Attribute Details
.crit ⇒ Object (readonly)
Returns the value of attribute crit.
11 12 13 |
# File 'lib/nsca/check.rb', line 11 def crit @crit end |
.label ⇒ Object (readonly)
Returns the value of attribute label.
11 12 13 |
# File 'lib/nsca/check.rb', line 11 def label @label end |
.max ⇒ Object (readonly)
Returns the value of attribute max.
11 12 13 |
# File 'lib/nsca/check.rb', line 11 def max @max end |
.min ⇒ Object (readonly)
Returns the value of attribute min.
11 12 13 |
# File 'lib/nsca/check.rb', line 11 def min @min end |
.unit ⇒ Object (readonly)
Returns the value of attribute unit.
11 12 13 |
# File 'lib/nsca/check.rb', line 11 def unit @unit end |
.warn ⇒ Object (readonly)
Returns the value of attribute warn.
11 12 13 |
# File 'lib/nsca/check.rb', line 11 def warn @warn end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
45 46 47 |
# File 'lib/nsca/check.rb', line 45 def value @value end |
Class Method Details
.clone(opts = nil) ⇒ Object
42 |
# 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) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# 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) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 |
.to_a ⇒ Object
41 |
# File 'lib/nsca/check.rb', line 41 def to_a() [label, unit, warn, crit, min, max] end |
.to_h ⇒ Object
40 |
# 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 ⇒ Object
39 |
# File 'lib/nsca/check.rb', line 39 def to_sym() label.to_sym end |
Instance Method Details
#crit ⇒ Object
50 |
# File 'lib/nsca/check.rb', line 50 def crit() self.class.crit end |
#label ⇒ Object
47 |
# File 'lib/nsca/check.rb', line 47 def label() self.class.label end |
#max ⇒ Object
52 |
# File 'lib/nsca/check.rb', line 52 def max() self.class.max end |
#min ⇒ Object
51 |
# File 'lib/nsca/check.rb', line 51 def min() self.class.min end |
#return_code ⇒ Object
61 62 63 64 65 66 67 |
# 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 ⇒ Object
53 |
# File 'lib/nsca/check.rb', line 53 def to_a() [label, value, unit, warn, crit, min, max] end |
#to_h ⇒ Object
57 58 59 |
# 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 ⇒ Object
54 |
# File 'lib/nsca/check.rb', line 54 def to_s() "'#{label.gsub /[\n'\|]/, ''}'=#{value}#{unit},#{warn},#{crit},#{min},#{max}" end |
#to_sym ⇒ Object
55 |
# File 'lib/nsca/check.rb', line 55 def to_sym() self.class.to_sym end |
#unit ⇒ Object
48 |
# File 'lib/nsca/check.rb', line 48 def unit() self.class.unit end |
#warn ⇒ Object
49 |
# File 'lib/nsca/check.rb', line 49 def warn() self.class.warn end |