Class: Prometheus::Client::Registry
- Inherits:
-
Object
- Object
- Prometheus::Client::Registry
show all
- Defined in:
- lib/prometheus/client/registry.rb
Overview
Defined Under Namespace
Classes: AlreadyRegisteredError
Instance Method Summary
collapse
-
#counter(name, docstring:, labels: [], preset_labels: {}, store_settings: {}) ⇒ Object
-
#exist?(name) ⇒ Boolean
-
#gauge(name, docstring:, labels: [], preset_labels: {}, store_settings: {}) ⇒ Object
-
#get(name) ⇒ Object
-
#histogram(name, docstring:, labels: [], preset_labels: {}, buckets: Histogram::DEFAULT_BUCKETS, store_settings: {}) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#metrics ⇒ Object
-
#register(metric) ⇒ Object
-
#summary(name, docstring:, labels: [], preset_labels: {}, store_settings: {}) ⇒ Object
-
#unregister(name) ⇒ Object
Constructor Details
Returns a new instance of Registry.
16
17
18
19
|
# File 'lib/prometheus/client/registry.rb', line 16
def initialize
@metrics = {}
@mutex = Mutex.new
end
|
Instance Method Details
#counter(name, docstring:, labels: [], preset_labels: {}, store_settings: {}) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/prometheus/client/registry.rb', line 40
def counter(name, docstring:, labels: [], preset_labels: {}, store_settings: {})
register(Counter.new(name,
docstring: docstring,
labels: labels,
preset_labels: preset_labels,
store_settings: store_settings))
end
|
#exist?(name) ⇒ Boolean
75
76
77
|
# File 'lib/prometheus/client/registry.rb', line 75
def exist?(name)
@mutex.synchronize { @metrics.key?(name) }
end
|
#gauge(name, docstring:, labels: [], preset_labels: {}, store_settings: {}) ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/prometheus/client/registry.rb', line 56
def gauge(name, docstring:, labels: [], preset_labels: {}, store_settings: {})
register(Gauge.new(name,
docstring: docstring,
labels: labels,
preset_labels: preset_labels,
store_settings: store_settings))
end
|
#get(name) ⇒ Object
79
80
81
|
# File 'lib/prometheus/client/registry.rb', line 79
def get(name)
@mutex.synchronize { @metrics[name.to_sym] }
end
|
#histogram(name, docstring:, labels: [], preset_labels: {}, buckets: Histogram::DEFAULT_BUCKETS, store_settings: {}) ⇒ Object
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/prometheus/client/registry.rb', line 64
def histogram(name, docstring:, labels: [], preset_labels: {},
buckets: Histogram::DEFAULT_BUCKETS,
store_settings: {})
register(Histogram.new(name,
docstring: docstring,
labels: labels,
preset_labels: preset_labels,
buckets: buckets,
store_settings: store_settings))
end
|
#metrics ⇒ Object
83
84
85
|
# File 'lib/prometheus/client/registry.rb', line 83
def metrics
@mutex.synchronize { @metrics.values }
end
|
#register(metric) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/prometheus/client/registry.rb', line 21
def register(metric)
name = metric.name
@mutex.synchronize do
if @metrics.key?(name.to_sym)
raise AlreadyRegisteredError, "#{name} has already been registered"
end
@metrics[name.to_sym] = metric
end
metric
end
|
#summary(name, docstring:, labels: [], preset_labels: {}, store_settings: {}) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/prometheus/client/registry.rb', line 48
def summary(name, docstring:, labels: [], preset_labels: {}, store_settings: {})
register(Summary.new(name,
docstring: docstring,
labels: labels,
preset_labels: preset_labels,
store_settings: store_settings))
end
|
#unregister(name) ⇒ Object
34
35
36
37
38
|
# File 'lib/prometheus/client/registry.rb', line 34
def unregister(name)
@mutex.synchronize do
@metrics.delete(name.to_sym)
end
end
|