Class: Metrics

Inherits:
Object
  • Object
show all
Defined in:
app/services/metrics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metric) ⇒ Metrics

Returns a new instance of Metrics.



8
9
10
# File 'app/services/metrics.rb', line 8

def initialize(metric)
  @metric = metric
end

Instance Attribute Details

#metricObject (readonly)

Returns the value of attribute metric.



6
7
8
# File 'app/services/metrics.rb', line 6

def metric
  @metric
end

Instance Method Details

#count(data = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'app/services/metrics.rb', line 12

def count(data = {})
  return unless enabled?

  client.count(metric, data.merge(
                         origin: "container-broker"
                       ))
rescue StandardError => e
  Rails.logger.warn("Error sending metrics to measures: #{e}")
end

#duration(data = {}) ⇒ Object



22
23
24
25
26
27
28
# File 'app/services/metrics.rb', line 22

def duration(data = {})
  if enabled?
    client.time(metric, data) { yield data if block_given? }
  else
    yield data if block_given?
  end
end