Class: Dasht::Metrics
- Inherits:
-
Object
- Object
- Dasht::Metrics
- Defined in:
- lib/dasht/metrics.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #get(metric, start_ts, end_ts) ⇒ Object
-
#initialize(parent) ⇒ Metrics
constructor
A new instance of Metrics.
- #set(metric, value, op, ts) ⇒ Object
- #trim_to(ts) ⇒ Object
Constructor Details
#initialize(parent) ⇒ Metrics
Returns a new instance of Metrics.
4 5 6 7 8 |
# File 'lib/dasht/metrics.rb', line 4 def initialize(parent) @parent = parent @metric_values = {} @metric_operations = {} end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/dasht/metrics.rb', line 3 def parent @parent end |
Instance Method Details
#get(metric, start_ts, end_ts) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/dasht/metrics.rb', line 19 def get(metric, start_ts, end_ts) metric = metric.to_s m = @metric_values[metric] return [] if m.nil? op = @metric_operations[metric] m.enum(start_ts, end_ts).to_a.flatten.send(op) end |
#set(metric, value, op, ts) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/dasht/metrics.rb', line 10 def set(metric, value, op, ts) metric = metric.to_s @metric_operations[metric] = op m = (@metric_values[metric] ||= Metric.new) m.append(value, ts) do |old_value, new_value| [old_value, new_value].compact.flatten.send(op) end end |
#trim_to(ts) ⇒ Object
27 28 29 30 31 |
# File 'lib/dasht/metrics.rb', line 27 def trim_to(ts) @metric_values.each do |k, v| v.trim_to(ts) end end |