Class: Monitors::Stats

Inherits:
BaseMonitor show all
Defined in:
lib/poolparty/monitors/monitors/stats_monitor.rb

Instance Attribute Summary collapse

Attributes inherited from BaseMonitor

#last_cloud_loaded_time, #log_file_path

Instance Method Summary collapse

Methods inherited from BaseMonitor

#after_close_callbacks, #before_close_callbacks, #env, inherited, #log, #my_cloud

Constructor Details

#initialize(env, o = {}) ⇒ Stats

Returns a new instance of Stats.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/poolparty/monitors/monitors/stats_monitor.rb', line 12

def initialize(env, o={})
  @env = env
  @request = Rack::Request.new env
  @response = Rack::Response.new
  
  begin
    @cloud = JSON.parse( open('/etc/poolparty/clouds.json' ).read )
    # @cloud = ::PoolParty::Cloud::Cloud.load_from_json(open('/etc/poolparty/clouds.json' ).read)
  rescue 
    @cloud = ::PoolParty::Default.dsl_options.merge({"options" =>
      {"rules" => {"expand"   => PoolParty::Default.expand_when,
                   "contract" => PoolParty::Default.contract_when
                  }
      }
    })        
  end
  make_aska_rules(@cloud["options"]["rules"])
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



9
10
11
# File 'lib/poolparty/monitors/monitors/stats_monitor.rb', line 9

def request
  @request
end

#responseObject

Returns the value of attribute response.



10
11
12
# File 'lib/poolparty/monitors/monitors/stats_monitor.rb', line 10

def response
  @response
end

Instance Method Details

#get(data = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/poolparty/monitors/monitors/stats_monitor.rb', line 31

def get(data=nil)
  begin
    if !request.params || request.params.empty?
      default_stats
    else
      stats[request.params[0].to_sym] ||= self.send(request.params[0])
      stats[request.params[0].to_sym]
      stats.to_json
    end
  rescue Exception => e
    "Error: #{e}".to_json
  end
end

#get_nominations(_nodes = []) ⇒ Object

alias to allow access thru http route GET /stats/nominations



46
47
48
# File 'lib/poolparty/monitors/monitors/stats_monitor.rb', line 46

def get_nominations(_nodes=[])
  nominations
end

#put(data) ⇒ Object Also known as: update



50
51
52
53
54
55
56
57
58
# File 'lib/poolparty/monitors/monitors/stats_monitor.rb', line 50

def put(data)
  if d = JSON.parse(request.params)
    hsh = d.reject {|ip, _node| ip == my_ip }
    stats.merge!(hsh)
    # handle_election
  else
    "boom"
  end
end