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

#docstring, #name, #preset_labels

Instance Method Summary collapse

Methods inherited from Metric

#get, #init_label_set, #initialize, #values, #with_labels

Constructor Details

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

Instance Method Details

#decrement(by: 1, labels: {}) ⇒ 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.)


32
33
34
35
# File 'lib/prometheus/client/gauge.rb', line 32

def decrement(by: 1, labels: {})
  label_set = label_set_for(labels)
  @store.increment(labels: label_set, by: -by)
end

#increment(by: 1, labels: {}) ⇒ 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
# File 'lib/prometheus/client/gauge.rb', line 25

def increment(by: 1, labels: {})
  label_set = label_set_for(labels)
  @store.increment(labels: label_set, by: by)
end

#set(value, labels: {}) ⇒ 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(value, labels: {})
  unless value.is_a?(Numeric)
    raise ArgumentError, 'value must be a number'
  end

  @store.set(labels: label_set_for(labels), val: value)
end

#typeObject


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

def type
  :gauge
end