Class: Prometheus::Client::Gauge

Inherits:
Metric
  • Object
show all
Defined in:
lib/prometheus/client/gauge.rb

Overview

A Gauge is a metric that exposes merely an instantaneous value or some snapshot thereof.

Instance Attribute Summary

Attributes inherited from Metric

#base_labels, #docstring, #name

Instance Method Summary collapse

Methods inherited from Metric

#get, #initialize, #values

Constructor Details

This class inherits a constructor from Prometheus::Client::Metric

Instance Method Details

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

Decrements Gauge value by 1 or subtracts the given value from the Gauge. (The value can be negative, resulting in a increase of the Gauge.)



35
36
37
38
39
40
41
# File 'lib/prometheus/client/gauge.rb', line 35

def decrement(labels = {}, by = 1)
  label_set = label_set_for(labels)
  synchronize do
    @values[label_set] ||= 0
    @values[label_set] -= by
  end
end

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

Increments Gauge value by 1 or adds the given value to the Gauge. (The value can be negative, resulting in a decrease of the Gauge.)



25
26
27
28
29
30
31
# File 'lib/prometheus/client/gauge.rb', line 25

def increment(labels = {}, by = 1)
  label_set = label_set_for(labels)
  synchronize do
    @values[label_set] ||= 0
    @values[label_set] += by
  end
end

#set(labels, value) ⇒ Object

Sets the value for the given label set



15
16
17
18
19
20
21
# File 'lib/prometheus/client/gauge.rb', line 15

def set(labels, value)
  unless value.is_a?(Numeric)
    raise ArgumentError, 'value must be a number'
  end

  @values[label_set_for(labels)] = value.to_f
end

#typeObject



10
11
12
# File 'lib/prometheus/client/gauge.rb', line 10

def type
  :gauge
end