Class: Monitors::BaseMonitor
- Defined in:
- lib/poolparty/monitors/base_monitor.rb
Direct Known Subclasses
Clock, Cloud, Elections, Favicon, Load, Memory, Neighborhood, Stats, PoolParty::MonitorDaemon
Instance Attribute Summary collapse
-
#last_cloud_loaded_time ⇒ Object
readonly
Returns the value of attribute last_cloud_loaded_time.
-
#log_file_path ⇒ Object
readonly
Returns the value of attribute log_file_path.
Class Method Summary collapse
Instance Method Summary collapse
- #after_close_callbacks ⇒ Object
- #before_close_callbacks ⇒ Object
- #env(env = @env) ⇒ Object
-
#initialize(env = nil) ⇒ BaseMonitor
constructor
A new instance of BaseMonitor.
- #log(msg) ⇒ Object
-
#my_cloud ⇒ Object
Load the cloud Reload the cloud if necessary after 60 seconds of cache time.
Constructor Details
#initialize(env = nil) ⇒ BaseMonitor
Returns a new instance of 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 (readonly)
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 (readonly)
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
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 |
#log(msg) ⇒ Object
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 |
#my_cloud ⇒ Object
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 |