Class: MonitoringInfo::MonitoringInfo
- Inherits:
-
Object
- Object
- MonitoringInfo::MonitoringInfo
- Defined in:
- lib/process_monitoring/monitoring_info.rb
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Class Method Summary collapse
- .get_html(hash, opts = {}) ⇒ Object
- .get_json(hash) ⇒ Object
- .get_remote_monitoring_info(host, port) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ MonitoringInfo
constructor
A new instance of MonitoringInfo.
Constructor Details
#initialize ⇒ MonitoringInfo
Returns a new instance of MonitoringInfo.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/process_monitoring/monitoring_info.rb', line 29 def initialize() @web_interface = Sinatra.new { set :bind, '0.0.0.0' get('/') { MonitoringInfo.get_json($process_vars.clone) } } @web_interface.set(:port, Params['process_monitoring_web_port']) @thread = Thread.new do @web_interface.run! end end |
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
27 28 29 |
# File 'lib/process_monitoring/monitoring_info.rb', line 27 def thread @thread end |
Class Method Details
.get_html(hash, opts = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/process_monitoring/monitoring_info.rb', line 51 def self.get_html (hash, opts = {}) return if !hash.is_a?(Hash) indent_level = opts.fetch(:indent_level) { 0 } out = " " * indent_level + "<ul>\n" hash.each do |key, value| out += " " * (indent_level + 2) + "<li><strong>#{key}:</strong>" if value.is_a?(Hash) out += "\n" + get_html(value, :indent_level => indent_level + 2) + " " * (indent_level + 2) + "</li>\n" else out += " <span>#{value}</span></li>\n" end end out += " " * indent_level + "</ul>\n" end |
.get_json(hash) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/process_monitoring/monitoring_info.rb', line 40 def self.get_json(hash) return '' if !hash.is_a?(Hash) entries = [] hash.each do |key, value| entries << "{#{key}:#{value}}" end return entries.join(" , ") end |
.get_remote_monitoring_info(host, port) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/process_monitoring/monitoring_info.rb', line 71 def self.get_remote_monitoring_info(host, port) begin JSON.parse(Net::HTTP.get(URI("http://#{host}:#{port}/"))) rescue Errno::ECONNREFUSED => e '' end end |