Class: Monitors::Stats
- Inherits:
-
BaseMonitor
- Object
- BaseMonitor
- Monitors::Stats
- Defined in:
- lib/poolparty/monitors/monitors/stats_monitor.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #get(data = nil) ⇒ Object
-
#initialize(env, o = {}) ⇒ Stats
constructor
A new instance of Stats.
- #put(data) ⇒ Object (also: #update)
Methods inherited from BaseMonitor
#after_close_callbacks, #before_close_callbacks
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 30 31 32 33 34 35 36 37 |
# 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 ) rescue @cloud = ::PoolParty::Default..merge({"options" => {"rules" => {"expand" => PoolParty::Default., "contract" => PoolParty::Default.contract_when } } }) end # Our cloud.options.rules looks like # {"expand_when" => "load > 0.9", "contract_when" => "load < 0.4"} # We set these as rules on ourselves so we can use aska to parse the rules. # Later, we can call vote_rules on ourself and we'll get back Aska::Rule(s) # which we'll call valid_rule? for each Rule and return the result @cloud["options"]["rules"].each do |name, rul| r = Aska::Rule.new(rul) rule(name) << r end # log << "#{::Time.now.strftime("%Y-%m-%d-%H-%M")}, #{stats.to_json}\n" end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
9 10 11 |
# File 'lib/poolparty/monitors/monitors/stats_monitor.rb', line 9 def request @request end |
#response ⇒ Object
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
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/poolparty/monitors/monitors/stats_monitor.rb', line 39 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}" end end |
#put(data) ⇒ Object Also known as: update
53 54 55 56 57 58 59 60 61 |
# File 'lib/poolparty/monitors/monitors/stats_monitor.rb', line 53 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 |