Class: Sematext::Metrics::Client
- Inherits:
-
Object
- Object
- Sematext::Metrics::Client
- Defined in:
- lib/sematext/metrics.rb
Class Method Summary collapse
Instance Method Summary collapse
- #epoch ⇒ Object
-
#initialize(sender) ⇒ Client
constructor
A new instance of Client.
- #send(datapoint) ⇒ Object
- #send_batch(datapoints) ⇒ Object
Constructor Details
#initialize(sender) ⇒ Client
Returns a new instance of Client.
54 55 56 57 58 |
# File 'lib/sematext/metrics.rb', line 54 def initialize(sender) @sender = sender @serializer = RawSerializer.new @validator = RawValidator.new end |
Class Method Details
.async(token) ⇒ Object
49 50 51 |
# File 'lib/sematext/metrics.rb', line 49 def async(token) Client.new(AsyncSender.new(token)) end |
.sync(token) ⇒ Object
45 46 47 |
# File 'lib/sematext/metrics.rb', line 45 def sync(token) Client.new(SyncSender.new(token)) end |
Instance Method Details
#epoch ⇒ Object
81 82 83 |
# File 'lib/sematext/metrics.rb', line 81 def epoch Time.now.to_i * 1000 end |
#send(datapoint) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/sematext/metrics.rb', line 60 def send datapoint return nil if datapoint.nil? result = send_batch [datapoint] result.first end |
#send_batch(datapoints) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sematext/metrics.rb', line 67 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 |