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, #labels, #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.)



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

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.)



29
30
31
32
# File 'lib/prometheus/client/gauge.rb', line 29

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

#set_to_current_time(labels: {}) ⇒ Object



23
24
25
# File 'lib/prometheus/client/gauge.rb', line 23

def set_to_current_time(labels: {})
  @store.set(labels: label_set_for(labels), val: Time.now.to_f)
end

#typeObject



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

def type
  :gauge
end