Class: CKnife::Monitor
- Inherits:
-
Object
- Object
- CKnife::Monitor
- Includes:
- BackgroundedPolling
- Defined in:
- lib/cknife/monitor.rb
Constant Summary
Constants included from BackgroundedPolling
BackgroundedPolling::BACKGROUND_POLL
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#consecutive_error_count ⇒ Object
Returns the value of attribute consecutive_error_count.
-
#last_error ⇒ Object
Returns the value of attribute last_error.
-
#last_polled_at ⇒ Object
Returns the value of attribute last_polled_at.
-
#last_result ⇒ Object
Returns the value of attribute last_result.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #before_poll ⇒ Object
- #handle_poll_result(response, request, result) ⇒ Object
-
#initialize(url, options = {}) ⇒ Monitor
constructor
A new instance of Monitor.
- #payload ⇒ Object
- #target_endpoint ⇒ Object
Constructor Details
#initialize(url, options = {}) ⇒ Monitor
Returns a new instance of Monitor.
9 10 11 12 13 14 15 |
# File 'lib/cknife/monitor.rb', line 9 def initialize(url, = {}) self.url = url self.active = true self.consecutive_error_count = 0 self.last_polled_at = nil self.api_key = [:api_key] if [:api_key] end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
5 6 7 |
# File 'lib/cknife/monitor.rb', line 5 def active @active end |
#api_key ⇒ Object
Returns the value of attribute api_key.
5 6 7 |
# File 'lib/cknife/monitor.rb', line 5 def api_key @api_key end |
#consecutive_error_count ⇒ Object
Returns the value of attribute consecutive_error_count.
5 6 7 |
# File 'lib/cknife/monitor.rb', line 5 def consecutive_error_count @consecutive_error_count end |
#last_error ⇒ Object
Returns the value of attribute last_error.
5 6 7 |
# File 'lib/cknife/monitor.rb', line 5 def last_error @last_error end |
#last_polled_at ⇒ Object
Returns the value of attribute last_polled_at.
5 6 7 |
# File 'lib/cknife/monitor.rb', line 5 def last_polled_at @last_polled_at end |
#last_result ⇒ Object
Returns the value of attribute last_result.
5 6 7 |
# File 'lib/cknife/monitor.rb', line 5 def last_result @last_result end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/cknife/monitor.rb', line 5 def url @url end |
Instance Method Details
#before_poll ⇒ Object
23 24 25 |
# File 'lib/cknife/monitor.rb', line 23 def before_poll self.last_result = nil end |
#handle_poll_result(response, request, result) ⇒ Object
27 28 29 |
# File 'lib/cknife/monitor.rb', line 27 def handle_poll_result(response, request, result) self.last_result = response.net_http_res.code.to_i end |
#payload ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cknife/monitor.rb', line 31 def payload res = `cat /proc/meminfo` lines = res.split("\n") matcher = /:\s+(\d+)/ lines[0] =~ matcher total = $1 lines[1] =~ matcher free = $1 stats = { :free => free.to_i, :total => total.to_i } end |
#target_endpoint ⇒ Object
17 18 19 20 21 |
# File 'lib/cknife/monitor.rb', line 17 def target_endpoint u = URI.parse(url) u.userinfo = "#{api_key}:#{api_key}" if api_key u.to_s end |