Class: WatchmonkeyCli::Checker
- Inherits:
-
Object
- Object
- WatchmonkeyCli::Checker
show all
- Includes:
- Helper
- Defined in:
- lib/watchmonkey_cli/checker.rb
Direct Known Subclasses
WatchmonkeyCli::Checkers::DevPry, WatchmonkeyCli::Checkers::FileExists, WatchmonkeyCli::Checkers::FtpAvailability, WatchmonkeyCli::Checkers::MysqlReplication, WatchmonkeyCli::Checkers::SslExpiration, WatchmonkeyCli::Checkers::TcpPort, WatchmonkeyCli::Checkers::Ts3License, WatchmonkeyCli::Checkers::UdpPort, WatchmonkeyCli::Checkers::UnixCpuGovernor, WatchmonkeyCli::Checkers::UnixDefaults, WatchmonkeyCli::Checkers::UnixDf, WatchmonkeyCli::Checkers::UnixLoad, WatchmonkeyCli::Checkers::UnixMdadm, WatchmonkeyCli::Checkers::UnixMemory, WatchmonkeyCli::Checkers::WwwAvailability
Defined Under Namespace
Modules: AppHelper
Classes: Result
Constant Summary
Constants included
from Helper
Helper::BYTE_UNITS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#_tolog(msg, meth = :log) ⇒ Object
-
#blank_config(tags = []) ⇒ Object
-
#check!(*a) ⇒ Object
-
#debug(msg, robj = nil) ⇒ Object
-
#enqueue(*args) ⇒ Object
-
#error(msg, robj = nil) ⇒ Object
-
#info(msg, robj = nil) ⇒ Object
-
#init ⇒ Object
= API = =================.
-
#initialize(app) ⇒ Checker
constructor
A new instance of Checker.
-
#local ⇒ Object
def to_s string = “#<#selfself.classself.class.name:#selfself.object_id ” fields = self.class.inspector_fields.map{|field| “#{field}: #selfself.send(field)”} string << fields.join(“, ”) << “>” end.
-
#rsafe(resultobj, max_retry: 3, &block) ⇒ Object
-
#safe(descriptor = nil, max_retry: 3, &block) ⇒ Object
-
#spawn_sub(which, *args) ⇒ Object
-
#start ⇒ Object
-
#stop ⇒ Object
Methods included from Helper
#human_filesize, #human_number, #human_seconds
Constructor Details
#initialize(app) ⇒ Checker
Returns a new instance of Checker.
144
145
146
147
|
# File 'lib/watchmonkey_cli/checker.rb', line 144
def initialize app
@app = app
send(:init) if respond_to?(:init)
end
|
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
142
143
144
|
# File 'lib/watchmonkey_cli/checker.rb', line 142
def app
@app
end
|
Class Method Details
.checker_name ⇒ Object
12
13
14
|
# File 'lib/watchmonkey_cli/checker.rb', line 12
def self.checker_name
@checker_name || self.name
end
|
.checker_name=(name) ⇒ Object
16
17
18
|
# File 'lib/watchmonkey_cli/checker.rb', line 16
def self.checker_name= name
@checker_name = name
end
|
.descendants ⇒ Object
Descendant tracking for inherited classes.
4
5
6
|
# File 'lib/watchmonkey_cli/checker.rb', line 4
def self.descendants
@descendants ||= []
end
|
.inherited(descendant) ⇒ Object
8
9
10
|
# File 'lib/watchmonkey_cli/checker.rb', line 8
def self.inherited(descendant)
descendants << descendant
end
|
.max_retry ⇒ Object
28
29
30
|
# File 'lib/watchmonkey_cli/checker.rb', line 28
def self.max_retry
@max_retry
end
|
.max_retry=(num) ⇒ Object
32
33
34
|
# File 'lib/watchmonkey_cli/checker.rb', line 32
def self.max_retry= num
@max_retry = num
end
|
.maxrt ⇒ Object
20
21
22
|
# File 'lib/watchmonkey_cli/checker.rb', line 20
def self.maxrt
@maxrt
end
|
.maxrt=(seconds) ⇒ Object
24
25
26
|
# File 'lib/watchmonkey_cli/checker.rb', line 24
def self.maxrt= seconds
@maxrt = seconds
end
|
Instance Method Details
#_tolog(msg, meth = :log) ⇒ Object
171
172
173
174
|
# File 'lib/watchmonkey_cli/checker.rb', line 171
def _tolog msg, meth = :log
return unless app.opts[:logfile]
app.logger.public_send(meth, msg)
end
|
#blank_config(tags = []) ⇒ Object
182
183
184
|
# File 'lib/watchmonkey_cli/checker.rb', line 182
def blank_config tags = []
Application::Configuration.new(app, nil, tags)
end
|
#check!(*a) ⇒ Object
277
278
279
280
|
# File 'lib/watchmonkey_cli/checker.rb', line 277
def check! *a
raise NotImplementedError, "a checker (#{self.class.name}) must implement `#check!' method!"
end
|
#debug(msg, robj = nil) ⇒ Object
156
157
158
159
160
161
162
|
# File 'lib/watchmonkey_cli/checker.rb', line 156
def debug msg, robj = nil
app.fire(:on_debug, msg, robj)
app.fire(:on_message, msg, robj)
return if app.opts[:quiet] || app.opts[:silent]
_tolog(msg, :debug)
app.puts app.c(msg, :black)
end
|
#enqueue(*args) ⇒ Object
270
271
272
273
274
275
|
# File 'lib/watchmonkey_cli/checker.rb', line 270
def enqueue *args
raise NotImplementedError, "a checker (#{self.class.name}) must implement `#enqueue' method!"
end
|
#error(msg, robj = nil) ⇒ Object
164
165
166
167
168
169
|
# File 'lib/watchmonkey_cli/checker.rb', line 164
def error msg, robj = nil
app.fire(:on_error, msg, robj)
app.fire(:on_message, msg, robj)
_tolog(msg, :error)
app.sync { app.error(msg) }
end
|
#info(msg, robj = nil) ⇒ Object
149
150
151
152
153
154
|
# File 'lib/watchmonkey_cli/checker.rb', line 149
def info msg, robj = nil
app.fire(:on_info, msg, robj)
return if app.opts[:quiet]
_tolog(msg, :info)
app.puts app.c(msg, :blue)
end
|
#init ⇒ Object
252
253
254
|
# File 'lib/watchmonkey_cli/checker.rb', line 252
def init
end
|
#local ⇒ Object
def to_s
string = "#<#{self.class.name}:#{self.object_id} "
fields = self.class.inspector_fields.map{|field| "#{field}: #{self.send(field)}"}
string << fields.join(", ") << ">"
end
192
193
194
|
# File 'lib/watchmonkey_cli/checker.rb', line 192
def local
@app.fetch_connection(:loopback, :local)
end
|
#rsafe(resultobj, max_retry: 3, &block) ⇒ Object
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
# File 'lib/watchmonkey_cli/checker.rb', line 216
def rsafe resultobj, max_retry: 3, &block
tries = 0
checker_ctrl = false
begin
tries += 1
checker_ctrl = catch(:checker, &block)
rescue StandardError => e
if checker_ctrl == :fatal
resultobj.sync do
resultobj.error! "fatal reason is `#{e.class}: #{e.message}'"
e.backtrace.each{|l| resultobj.debug "\t\t#{l}" }
resultobj.dump!
end
elsif tries <= max_retry
resultobj.sync do
resultobj.error! "retry #{tries} reason is `#{e.class}: #{e.message}'"
e.backtrace.each{|l| resultobj.debug "\t\t#{l}" }
resultobj.dump!
end
unless $wm_runtime_exiting
sleep 1
retry
end
else
resultobj.error! "retries exceeded"
resultobj.dump!
end
end
end
|
#safe(descriptor = nil, max_retry: 3, &block) ⇒ Object
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
# File 'lib/watchmonkey_cli/checker.rb', line 196
def safe descriptor = nil, max_retry: 3, &block
tries = 0
begin
tries += 1
block.call
rescue StandardError => e
unless tries > max_retry
app.sync do
error "#{descriptor}retry #{tries} reason is `#{e.class}: #{e.message}'"
e.backtrace.each{|l| debug "\t\t#{l}" }
end
unless $wm_runtime_exiting
sleep 1
retry
end
end
error "#{descriptor}retries exceeded"
end
end
|
#spawn_sub(which, *args) ⇒ Object
176
177
178
179
180
|
# File 'lib/watchmonkey_cli/checker.rb', line 176
def spawn_sub which, *args
if sec = app.checkers[which.to_s]
sec.enqueue(*args)
end
end
|
#start ⇒ Object
256
257
258
259
|
# File 'lib/watchmonkey_cli/checker.rb', line 256
def start
end
|
#stop ⇒ Object
261
262
263
264
265
266
267
268
|
# File 'lib/watchmonkey_cli/checker.rb', line 261
def stop
end
|