class Metrics::Drivers::L2Met::Lines

Responsible for taking a prefix, and an array of measurements, and returning an array of log lines that are limited to 1024 characters per line.

Constants

DELIMITER
MAX_LEN

Attributes

max[R]
measurements[R]
source[R]

Public Class Methods

new(source, measurements) click to toggle source
# File lib/metrics/drivers/l2met.rb, line 64
def initialize(source, measurements)
  @source = "source=#{source}"
  @measurements = measurements
  @max = MAX_LEN - @source.length + DELIMITER.length * 2
end

Public Instance Methods

each(&block) click to toggle source
# File lib/metrics/drivers/l2met.rb, line 70
def each(&block)
  measurements.each(&block)
end
lines() click to toggle source

Groups the array of measurements into an array of log lines, each line prefixed with the source.

Example

# This:
['measure#rack.request=1', ..., 'measure#rack.request.time=200ms']

# Into this:
['source=app measure#rack.request=1', 'source=app measure#rack.request.time=200ms', ...]

Returns an Array.

# File lib/metrics/drivers/l2met.rb, line 86
def lines
  total = 0
  chunk { |measurement|
    total += measurement.length + DELIMITER.length * 2
    total / max
  }.map { |_, line|
    [source, line].join(DELIMITER)
  }
end