lib/instrumental/agent.rb in instrumental-0.1.5 vs lib/instrumental/agent.rb in instrumental-0.1.6

- old
+ new

@@ -23,10 +23,14 @@ @@queue[:measure][name] << value end end end + def milestone(name = Time.now.utc.to_s) + post_response("#{ config.path }/milestone", { :name => name }) + end + def setup_and_run @intervalometer = Intervalometer.new(config.report_interval) config.logger.debug("Starting agent. Reporting every #{config.report_interval} seconds") @thread = Thread.new do @@ -68,30 +72,27 @@ Instrumental.config end def send_report(type, name, value) if type == :measure - attributes = { :values => value } + params = { :values => value } else - attributes = { :value => value } + params = { :value => value } end - attributes[:name] = URI.escape("#{ config.name_prefix }#{ name }") - attributes[:api_key] = config.api_key - - # attributes_string = attributes.to_a.map{ |a| a.join('=') }.join('&') - path = "#{ config.path }#{ type }" - # config.logger.debug("Calling #{ path }") - response = post_response(path, attributes) + response = post_response(path, params) unless response.is_a?(Net::HTTPSuccess) config.logger.error "[Instrumental] Unexpected response from server (#{ response.code }): #{ response.message }" end end def post_response(path, params) + params[:api_key] = config.api_key + params[:name] = URI.escape("#{ config.name_prefix }#{ params[:name] }") + req = Net::HTTP::Post.new(path) req.set_form_data(params) Net::HTTP.new(config.host, config.port).start { |h| h.request(req) } end \ No newline at end of file