class Sematext::Metrics::Client
Public Class Methods
async(token, receiver_url = nil)
click to toggle source
# File lib/sematext/metrics.rb, line 57 def async(token, receiver_url = nil) url, path = parse_url(receiver_url) if receiver_url Client.new(AsyncSender.new(token, url, path)) end
new(sender)
click to toggle source
# File lib/sematext/metrics.rb, line 69 def initialize(sender) @sender = sender @serializer = RawSerializer.new @validator = RawValidator.new end
sync(token, receiver_url = nil)
click to toggle source
# File lib/sematext/metrics.rb, line 52 def sync(token, receiver_url = nil) url, path = parse_url(receiver_url) if receiver_url Client.new(SyncSender.new(token, url, path)) end
Private Class Methods
parse_url(url)
click to toggle source
# File lib/sematext/metrics.rb, line 63 def parse_url(url) uri = URI.parse(url) ["#{uri.scheme}://#{uri.host}:#{uri.port}", uri.path] end
Public Instance Methods
epoch()
click to toggle source
# File lib/sematext/metrics.rb, line 96 def epoch Time.now.to_i * 1000 end
send(datapoint)
click to toggle source
# File lib/sematext/metrics.rb, line 75 def send datapoint return nil if datapoint.nil? result = send_batch [datapoint] result.first end
send_batch(datapoints)
click to toggle source
# File lib/sematext/metrics.rb, line 82 def send_batch datapoints return nil if datapoints.empty? datapoints.each do |dp| @validator.validate(dp) dp[:timestamp] = epoch unless dp[:timestamp] end datapoints.each_slice(Settings::MAX_DP_PER_REQUEST).map do |slice| serialized = @serializer.serialize_datapoints(slice) @sender.send serialized end end