Class: Wildcloud::Router::Monitor
- Inherits:
-
Object
- Object
- Wildcloud::Router::Monitor
- Defined in:
- lib/wildcloud/router/monitor.rb
Instance Method Summary collapse
-
#initialize ⇒ Monitor
constructor
A new instance of Monitor.
- #report ⇒ Object
- #request(target, time, inbound, outbound) ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize ⇒ Monitor
Returns a new instance of Monitor.
10 11 12 13 14 15 |
# File 'lib/wildcloud/router/monitor.rb', line 10 def initialize @channel = AMQP::Channel.new(Core.instance.amqp) @topic = @channel.topic('wildcloud.monitor') @data = setup EventMachine.add_periodic_timer(1, &method(:report)) end |
Instance Method Details
#report ⇒ Object
17 18 19 20 21 |
# File 'lib/wildcloud/router/monitor.rb', line 17 def report data, @data = @data, setup puts data.inspect @topic.publish(JSON.dump(data), :routing_key => 'router') end |
#request(target, time, inbound, outbound) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/wildcloud/router/monitor.rb', line 35 def request(target, time, inbound, outbound) return unless target target = "#{target['address']}:#{target['port']}" @data[:count] += 1 @data[:inbound] += inbound @data[:outbound] += outbound @data[:time] += time #@data[:target][target] ||= {:count => 0, :outbound => 0, :inbound => 0, :time => 0} #@data[:target][target][:count] += 1 #@data[:target][target][:time] += time #@data[:target][target][:inbound] += inbound #@data[:target][target][:outbound] += outbound end |
#setup ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/wildcloud/router/monitor.rb', line 23 def setup { :published_at => Time.now.to_i, :node => Router.configuration['node']['name'], :count => 0, :inbound => 0, :outbound => 0, :time => 0, :target => {}, } end |