Class: Ns24::Dashing::Collector::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/ns24-dashing-collector/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



10
11
12
13
# File 'lib/ns24-dashing-collector/runner.rb', line 10

def initialize
  # @collectors = [Queues, Events, Apps, Usership].map(&:new)
  @collectors = [Queues, Events].map(&:new)
end

Instance Attribute Details

#collectorsObject (readonly)

Returns the value of attribute collectors.



15
16
17
# File 'lib/ns24-dashing-collector/runner.rb', line 15

def collectors
  @collectors
end

Instance Method Details

#post(metric, info) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ns24-dashing-collector/runner.rb', line 30

def post metric, info
  info.merge! auth_token: ENV['AUTH_TOKEN']

  uri = URI.parse("http://ns24-dashingboard.herokuapp.com/widgets/#{metric}")
  http = Net::HTTP.new(uri.host, uri.port)

  request = Net::HTTP::Post.new(uri.request_uri)
  request.body = info.to_json

  # handle errors here
  response = http.request(request)

  unless response.code =~ /2\d\d/
    puts "metric: #{metric}, payload: #{info}"
    puts "Error: #{response.body}"
  end
end

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ns24-dashing-collector/runner.rb', line 17

def run
  # loop here
  loop do
    collectors.each do |cl|
      m, i = cl.metric, cl.info
      post m, i
      # puts "#{m}: #{i}"
    end

    sleep(2)
  end
end