Class: Monitors::BaseMonitor
- Inherits:
-
Object
show all
- Defined in:
- lib/poolparty/monitors/base_monitor.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(env = nil) ⇒ BaseMonitor
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/poolparty/monitors/base_monitor.rb', line 23
def initialize(env=nil)
@env=env
log_filename = "poolparty_monitor.log"
@log_file_path = "/var/log/poolparty/#{log_filename}"
unless ::File.file?(log_file_path)
::FileUtils.mkdir_p ::File.dirname(log_file_path) unless ::File.directory?(::File.dirname(log_file_path))
::File.open(log_file_path, 'a+') {|f| f << "------ #{Time.now} ------"}
log_file_path
end
end
|
Instance Attribute Details
#last_cloud_loaded_time ⇒ Object
Returns the value of attribute last_cloud_loaded_time.
15
16
17
|
# File 'lib/poolparty/monitors/base_monitor.rb', line 15
def last_cloud_loaded_time
@last_cloud_loaded_time
end
|
#log_file_path ⇒ Object
Returns the value of attribute log_file_path.
15
16
17
|
# File 'lib/poolparty/monitors/base_monitor.rb', line 15
def log_file_path
@log_file_path
end
|
Class Method Details
.inherited(subclass) ⇒ Object
17
18
19
20
21
|
# File 'lib/poolparty/monitors/base_monitor.rb', line 17
def self.inherited(subclass)
unless Monitors.available.include?(subclass)
Monitors.available << subclass unless subclass.to_s =~ /MonitorDaemon/
end
end
|
Instance Method Details
#after_close_callbacks ⇒ Object
69
70
71
|
# File 'lib/poolparty/monitors/base_monitor.rb', line 69
def after_close_callbacks
@after_close_callbacks ||= []
end
|
#before_close_callbacks ⇒ Object
66
67
68
|
# File 'lib/poolparty/monitors/base_monitor.rb', line 66
def before_close_callbacks
@before_close_callbacks ||= []
end
|
#env(env = @env) ⇒ Object
35
36
37
|
# File 'lib/poolparty/monitors/base_monitor.rb', line 35
def env(env=@env)
@env=env
end
|
73
74
75
76
|
# File 'lib/poolparty/monitors/base_monitor.rb', line 73
def log(msg)
log_file.flush
log_file << "[INFO] - #{Time.now} -- #{msg}\n"
end
|
Load the cloud Reload the cloud if necessary after 60 seconds of cache time
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/poolparty/monitors/base_monitor.rb', line 53
def my_cloud
@my_cloud = nil if last_cloud_loaded_time && last_cloud_loaded_time > 60
@my_cloud ||= begin
require '/etc/poolparty/clouds.rb'
name = open("/etc/poolparty/cloud_name").read
last_cloud_loaded_time = Time.now.to_i
clouds[name.chomp.to_sym]
rescue Exception => e
JSON.parse( open('/etc/poolparty/clouds.json' ).read )
end
end
|