Class: Sumologic::Metrics::MetricBatch

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Defaults::MetricBatch, Logging
Defined in:
lib/sumologic/metrics/metric_batch.rb

Overview

A batch of ‘metric`s to be sent to the API

Constant Summary

Constants included from Defaults::MetricBatch

Defaults::MetricBatch::MAX_BYTES, Defaults::MetricBatch::MAX_SIZE

Instance Method Summary collapse

Methods included from Logging

included, #logger

Constructor Details

#initialize(max_metric_count) ⇒ MetricBatch

Returns a new instance of MetricBatch.



11
12
13
14
15
# File 'lib/sumologic/metrics/metric_batch.rb', line 11

def initialize(max_metric_count)
  @metrics = []
  @max_metric_count = max_metric_count
  @size = 0
end

Instance Method Details

#<<(metric) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/sumologic/metrics/metric_batch.rb', line 17

def <<(metric)
  if metric.too_big?
    logger.error('a metric exceeded the maximum allowed size')
  else
    @metrics << metric
    @size += metric.size + 2 # One byte for new line
  end
end

#clearObject



30
31
32
33
# File 'lib/sumologic/metrics/metric_batch.rb', line 30

def clear
  @metrics.clear
  @json = 0
end

#full?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/sumologic/metrics/metric_batch.rb', line 26

def full?
  item_count_exhausted? || size_exhausted?
end

#to_sObject



35
36
37
# File 'lib/sumologic/metrics/metric_batch.rb', line 35

def to_s
  @metrics.join("\n")
end