Class: Prometheus::Client::Metric
- Inherits:
-
Object
- Object
- Prometheus::Client::Metric
- Defined in:
- lib/prometheus/client/metric.rb
Overview
Metric
Instance Method Summary collapse
-
#default ⇒ Object
Default value.
-
#get(labels = {}) ⇒ Object
Returns the value for the given label set.
-
#initialize ⇒ Metric
constructor
A new instance of Metric.
-
#set(labels, value) ⇒ Object
Sets the value for the given label set.
-
#to_json(*json) ⇒ Object
Generates JSON representation.
-
#type ⇒ Object
Returns the metric type.
-
#value ⇒ Object
Returns all values.
Constructor Details
#initialize ⇒ Metric
Returns a new instance of Metric.
8 9 10 11 |
# File 'lib/prometheus/client/metric.rb', line 8 def initialize @mutex = Mutex.new @values = Hash.new(default) end |
Instance Method Details
#default ⇒ Object
Default value
14 15 16 |
# File 'lib/prometheus/client/metric.rb', line 14 def default nil end |
#get(labels = {}) ⇒ Object
Returns the value for the given label set
31 32 33 |
# File 'lib/prometheus/client/metric.rb', line 31 def get(labels = {}) @values[label_set_for(labels)] end |
#set(labels, value) ⇒ Object
Sets the value for the given label set
36 37 38 |
# File 'lib/prometheus/client/metric.rb', line 36 def set(labels, value) @values[label_set_for(labels)] = value end |
#to_json(*json) ⇒ Object
Generates JSON representation
41 42 43 44 45 46 |
# File 'lib/prometheus/client/metric.rb', line 41 def to_json(*json) { 'type' => type, 'value' => value }.to_json(*json) end |
#type ⇒ Object
Returns the metric type
19 20 21 |
# File 'lib/prometheus/client/metric.rb', line 19 def type raise NotImplementedError end |
#value ⇒ Object
Returns all values
24 25 26 27 28 |
# File 'lib/prometheus/client/metric.rb', line 24 def value @values.map do |labels, value| { :labels => labels, :value => value } end end |