Class: Metrics::Drivers::L2Met::Lines
- Inherits:
-
Object
- Object
- Metrics::Drivers::L2Met::Lines
- Includes:
- Enumerable
- Defined in:
- lib/metrics/drivers/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.
62 63 64 |
# File 'lib/metrics/drivers/l2met.rb', line 62 def max @max end |
#measurements ⇒ Object (readonly)
Returns the value of attribute measurements.
61 62 63 |
# File 'lib/metrics/drivers/l2met.rb', line 61 def measurements @measurements end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
60 61 62 |
# File 'lib/metrics/drivers/l2met.rb', line 60 def source @source end |
Instance Method Details
#each(&block) ⇒ Object
70 71 72 |
# File 'lib/metrics/drivers/l2met.rb', line 70 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.
86 87 88 89 90 91 92 93 94 |
# 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 |