Class: Yabeda::Summary

Inherits:
Metric
  • Object
show all
Defined in:
lib/yabeda/summary.rb

Overview

Base class for complex metric for measuring time values that allow to calculate averages, percentiles, and so on.

Instance Attribute Summary

Attributes inherited from Metric

#aggregation, #comment, #group, #name, #per, #tags, #unit

Instance Method Summary collapse

Methods inherited from Metric

#get, #initialize, #inspect, #values

Constructor Details

This class inherits a constructor from Yabeda::Metric

Instance Method Details

#observe(tags, value = nil) ⇒ Object

rubocop: disable Metrics/MethodLength



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/yabeda/summary.rb', line 8

def observe(tags, value = nil)
  if value.nil? ^ block_given?
    raise ArgumentError, "You must provide either numeric value or block for Yabeda::Summary#observe!"
  end

  if block_given?
    starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    yield
    value = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting)
  end

  all_tags = ::Yabeda::Tags.build(tags, group)
  values[all_tags] = value
  ::Yabeda.adapters.each do |_, adapter|
    adapter.perform_summary_observe!(self, all_tags, value)
  end
  value
end