Class: Eye::Checker
Defined Under Namespace
Classes: Cpu, Defer, FileCTime, FileSize, Http, Memory, Socket
Constant Summary
collapse
- TYPES =
{:memory => "Memory", :cpu => "Cpu", :http => "Http",
:ctime => "FileCTime", :fsize => "FileSize", :socket => "Socket"}
Instance Attribute Summary collapse
#defaults, #should_bes, #validates, #variants
#logger
Class Method Summary
collapse
Instance Method Summary
collapse
inherited, param, validate
Constructor Details
#initialize(pid, options = {}, logger_prefix = nil) ⇒ Checker
Returns a new instance of Checker.
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/eye/checker.rb', line 30
def initialize(pid, options = {}, logger_prefix = nil)
@pid = pid
@options = options
@type = options[:type]
@logger = Eye::Logger.new(logger_prefix, "check:#{check_name}")
debug "create checker, with #{options}"
@value = nil
@values = Eye::Utils::Tail.new(max_tries)
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
14
15
16
|
# File 'lib/eye/checker.rb', line 14
def options
@options
end
|
#pid ⇒ Object
Returns the value of attribute pid.
14
15
16
|
# File 'lib/eye/checker.rb', line 14
def pid
@pid
end
|
#type ⇒ Object
Returns the value of attribute type.
14
15
16
|
# File 'lib/eye/checker.rb', line 14
def type
@type
end
|
#value ⇒ Object
Returns the value of attribute value.
14
15
16
|
# File 'lib/eye/checker.rb', line 14
def value
@value
end
|
#values ⇒ Object
Returns the value of attribute values.
14
15
16
|
# File 'lib/eye/checker.rb', line 14
def values
@values
end
|
Class Method Details
.create(pid, options = {}, logger_prefix = nil) ⇒ Object
22
23
24
|
# File 'lib/eye/checker.rb', line 22
def self.create(pid, options = {}, logger_prefix = nil)
get_class(options[:type]).new(pid, options, logger_prefix)
end
|
.get_class(type) ⇒ Object
16
17
18
19
20
|
# File 'lib/eye/checker.rb', line 16
def self.get_class(type)
klass = eval("Eye::Checker::#{TYPES[type]}") rescue nil
raise "Unknown checker #{type}" unless klass
klass
end
|
.validate!(options) ⇒ Object
26
27
28
|
# File 'lib/eye/checker.rb', line 26
def self.validate!(options)
get_class(options[:type]).validate(options)
end
|
Instance Method Details
#check ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/eye/checker.rb', line 51
def check
@value = get_value
@values << {:value => @value, :good => good?(value)}
result = true
if @values.size == max_tries
bad_count = @values.count{|v| !v[:good] }
result = false if bad_count >= min_tries
end
info "#{last_human_values} => #{result ? 'OK' : 'Fail'}"
result
end
|
#check_name ⇒ Object
80
81
82
|
# File 'lib/eye/checker.rb', line 80
def check_name
@check_name ||= @type.to_s
end
|
#get_value ⇒ Object
66
67
68
|
# File 'lib/eye/checker.rb', line 66
def get_value
raise 'Realize me'
end
|
#good?(value) ⇒ Boolean
true if check ok false if check bad
76
77
78
|
# File 'lib/eye/checker.rb', line 76
def good?(value)
raise 'Realize me'
end
|
#human_value(value) ⇒ Object
70
71
72
|
# File 'lib/eye/checker.rb', line 70
def human_value(value)
value.to_s
end
|
#last_human_values ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/eye/checker.rb', line 42
def last_human_values
h_values = @values.map do |v|
sign = v[:good] ? '' : '*'
sign + human_value(v[:value]).to_s
end
'[' + h_values * ', ' + ']'
end
|
#max_tries ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/eye/checker.rb', line 84
def max_tries
@max_tries ||= if times
if times.is_a?(Array)
times[-1].to_i
else
times.to_i
end
else
1
end
end
|
#min_tries ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/eye/checker.rb', line 96
def min_tries
@min_tries ||= if times
if times.is_a?(Array)
times[0].to_i
else
max_tries
end
else
max_tries
end
end
|
#previous_value ⇒ Object
108
109
110
|
# File 'lib/eye/checker.rb', line 108
def previous_value
@values[-1][:value] if @values.present?
end
|