Class: PrometheusExporter::Metric::Counter
- Inherits:
-
Base
- Object
- Base
- PrometheusExporter::Metric::Counter
show all
- Defined in:
- lib/prometheus_exporter/metric/counter.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#help, #name
Instance Method Summary
collapse
Methods inherited from Base
default_aggregation, default_aggregation=, default_labels, default_labels=, default_prefix, default_prefix=, #from_json, #labels_text, #prefix, #to_prometheus_text
Constructor Details
#initialize(name, help) ⇒ Counter
Returns a new instance of Counter.
7
8
9
10
|
# File 'lib/prometheus_exporter/metric/counter.rb', line 7
def initialize(name, help)
super
reset!
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5
6
7
|
# File 'lib/prometheus_exporter/metric/counter.rb', line 5
def data
@data
end
|
Instance Method Details
#decrement(labels = {}, value = 1) ⇒ Object
44
45
46
47
|
# File 'lib/prometheus_exporter/metric/counter.rb', line 44
def decrement(labels = {}, value = 1)
@data[labels] ||= 0
@data[labels] -= value
end
|
#increment(labels = {}, value = 1) ⇒ Object
39
40
41
42
|
# File 'lib/prometheus_exporter/metric/counter.rb', line 39
def increment(labels = {}, value = 1)
@data[labels] ||= 0
@data[labels] += value
end
|
#metric_text ⇒ Object
20
21
22
23
24
|
# File 'lib/prometheus_exporter/metric/counter.rb', line 20
def metric_text
@data.map do |labels, value|
"#{prefix(@name)}#{labels_text(labels)} #{value}"
end.join("\n")
end
|
#observe(increment = 1, labels = {}) ⇒ Object
34
35
36
37
|
# File 'lib/prometheus_exporter/metric/counter.rb', line 34
def observe(increment = 1, labels = {})
@data[labels] ||= 0
@data[labels] += increment
end
|
#remove(labels) ⇒ Object
30
31
32
|
# File 'lib/prometheus_exporter/metric/counter.rb', line 30
def remove(labels)
@data.delete(labels)
end
|
#reset(labels = {}, value = 0) ⇒ Object
49
50
51
|
# File 'lib/prometheus_exporter/metric/counter.rb', line 49
def reset(labels = {}, value = 0)
@data[labels] = value
end
|
#reset! ⇒ Object
16
17
18
|
# File 'lib/prometheus_exporter/metric/counter.rb', line 16
def reset!
@data = {}
end
|
#to_h ⇒ Object
26
27
28
|
# File 'lib/prometheus_exporter/metric/counter.rb', line 26
def to_h
@data.dup
end
|
#type ⇒ Object
12
13
14
|
# File 'lib/prometheus_exporter/metric/counter.rb', line 12
def type
"counter"
end
|