class Wavefront::Writer::Api
Send points direct to Wavefront's API. This requires an endpoint, a token, and HTTPS egress.
Public Instance Methods
api_path()
click to toggle source
# File lib/wavefront-sdk/writers/api.rb, line 17 def api_path '/report' end
open()
click to toggle source
# File lib/wavefront-sdk/writers/api.rb, line 13 def open @conn = Wavefront::ApiCaller.new(self, creds, opts) end
send_point(body)
click to toggle source
# File lib/wavefront-sdk/writers/api.rb, line 33 def send_point(body) _send_point(body) summary.sent += body.size true rescue StandardError => e summary.unsent += body.size logger.log('WARNING: failed to send point(s).') logger.log(e.to_s, :debug) false end
validate_credentials(creds)
click to toggle source
# File lib/wavefront-sdk/writers/api.rb, line 21 def validate_credentials(creds) unless creds.key?(:endpoint) && creds[:endpoint] raise(Wavefront::Exception::CredentialError, 'credentials must contain API endpoint') end return true if creds.key?(:token) && creds[:token] raise(Wavefront::Exception::CredentialError, 'credentials must contain API token') end
Private Instance Methods
_send_point(body)
click to toggle source
Send points in batches of a hundred. I'm not sure exactly how much the API can cope with in a single call, so this might change.
# File lib/wavefront-sdk/writers/api.rb, line 59 def _send_point(body) body.each_slice(100) do |p| conn.post('/?f=wavefront', p.join("\n"), 'application/octet-stream') end end
write_loop(points)
click to toggle source
# File lib/wavefront-sdk/writers/api.rb, line 46 def write_loop(points) body = points.map do |p| p[:ts] = p[:ts].to_i if p[:ts].is_a?(Time) hash_to_wf(p) end send_point(body) end