Class: Ns24::Dashing::Collector::Runner
- Inherits:
-
Object
- Object
- Ns24::Dashing::Collector::Runner
- Defined in:
- lib/ns24-dashing-collector/runner.rb
Instance Attribute Summary collapse
-
#collectors ⇒ Object
readonly
Returns the value of attribute collectors.
Instance Method Summary collapse
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #post(metric, info) ⇒ Object
- #run ⇒ Object
Constructor Details
Instance Attribute Details
#collectors ⇒ Object (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 |
#run ⇒ Object
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 |