Class: Metrics::Formatters::L2Met::Lines
- Inherits:
-
Object
- Object
- Metrics::Formatters::L2Met::Lines
- Includes:
- Enumerable
- Defined in:
- lib/metrics/formatters/l2met.rb
Overview
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.
Constant Summary collapse
- MAX_LEN =
1024.freeze
- DELIMITER =
' '.freeze
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#measurements ⇒ Object
readonly
Returns the value of attribute measurements.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(source, measurements) ⇒ Lines
constructor
A new instance of Lines.
-
#lines ⇒ Object
Groups the array of measurements into an array of log lines, each line prefixed with the source.
Constructor Details
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
47 48 49 |
# File 'lib/metrics/formatters/l2met.rb', line 47 def max @max end |
#measurements ⇒ Object (readonly)
Returns the value of attribute measurements.
46 47 48 |
# File 'lib/metrics/formatters/l2met.rb', line 46 def measurements @measurements end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
45 46 47 |
# File 'lib/metrics/formatters/l2met.rb', line 45 def source @source end |
Instance Method Details
#each(&block) ⇒ Object
55 56 57 |
# File 'lib/metrics/formatters/l2met.rb', line 55 def each(&block) measurements.each(&block) end |
#lines ⇒ Object
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.
71 72 73 74 75 76 77 78 79 |
# File 'lib/metrics/formatters/l2met.rb', line 71 def lines total = 0 chunk { |measurement| total += measurement.length + DELIMITER.length * 2 total / max }.map { |_, line| [source, line].join(DELIMITER) } end |