Class: Yabeda::Gauge

Inherits:
Metric show all
Defined in:
lib/yabeda/gauge.rb

Overview

Arbitrary value, can be changed in both sides

Instance Attribute Summary

Attributes inherited from Metric

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

Instance Method Summary collapse

Methods inherited from Metric

#adapters, #get, #increment_value, #initialize, #inspect

Constructor Details

This class inherits a constructor from Yabeda::Metric

Instance Method Details

#decrement(tags = {}, by: 1) ⇒ Object

Convenience method to decrement current gauge value for given set of tags by the given decrement value

Parameters:

  • tags (defaults to: {})

    HashSymbol=>#to_s tags to identify the gauge

  • by (Integer) (defaults to: 1)

    decrement value



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/yabeda/gauge.rb', line 36

def decrement(*args)
  tags, by = Counter.parse_args(*args)
  all_tags = ::Yabeda::Tags.build(tags, group)
  next_value = increment_value(all_tags, by: -by)
  adapters.each_value do |adapter|
    if adapter.perform_gauge_increment!(self, all_tags, -by).nil?
      adapter.perform_gauge_set!(self, all_tags, next_value)
    end
  end
  next_value
end

#increment(tags = {}, by: 1) ⇒ Object

Convenience method to increment current gauge value for given set of tags by the given increment value

Parameters:

  • tags (defaults to: {})

    HashSymbol=>#to_s tags to identify the gauge

  • by (Integer) (defaults to: 1)

    increment value



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/yabeda/gauge.rb', line 20

def increment(*args)
  tags, by = Counter.parse_args(*args)
  all_tags = ::Yabeda::Tags.build(tags, group)
  next_value = increment_value(all_tags, by: by)
  adapters.each_value do |adapter|
    if adapter.perform_gauge_increment!(self, all_tags, by).nil?
      adapter.perform_gauge_set!(self, all_tags, next_value)
    end
  end
  next_value
end

#set(tags, value) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/yabeda/gauge.rb', line 6

def set(tags, value)
  all_tags = ::Yabeda::Tags.build(tags, group)
  atomic_value = values[all_tags] ||= Concurrent::Atom.new(0)
  atomic_value.swap { |_| value }
  adapters.each_value do |adapter|
    adapter.perform_gauge_set!(self, all_tags, value)
  end
  value
end