Class: Prometheus::Client::Metric
- Inherits:
-
Object
- Object
- Prometheus::Client::Metric
- Defined in:
- lib/prometheus/client/metric.rb
Overview
Metric
Instance Attribute Summary collapse
-
#base_labels ⇒ Object
readonly
Returns the value of attribute base_labels.
-
#docstring ⇒ Object
readonly
Returns the value of attribute docstring.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#get(labels = {}) ⇒ Object
Returns the value for the given label set.
-
#initialize(name, docstring, base_labels = {}) ⇒ Metric
constructor
A new instance of Metric.
-
#type ⇒ Object
Returns the metric type.
-
#values ⇒ Object
Returns all label sets with their values.
Constructor Details
#initialize(name, docstring, base_labels = {}) ⇒ Metric
Returns a new instance of Metric.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/prometheus/client/metric.rb', line 12 def initialize(name, docstring, base_labels = {}) @mutex = Mutex.new @validator = LabelSetValidator.new @values = Hash.new { |hash, key| hash[key] = default } validate_name(name) validate_docstring(docstring) @validator.valid?(base_labels) @name = name @docstring = docstring @base_labels = base_labels end |
Instance Attribute Details
#base_labels ⇒ Object (readonly)
Returns the value of attribute base_labels.
10 11 12 |
# File 'lib/prometheus/client/metric.rb', line 10 def base_labels @base_labels end |
#docstring ⇒ Object (readonly)
Returns the value of attribute docstring.
10 11 12 |
# File 'lib/prometheus/client/metric.rb', line 10 def docstring @docstring end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/prometheus/client/metric.rb', line 10 def name @name end |
Instance Method Details
#get(labels = {}) ⇒ Object
Returns the value for the given label set
32 33 34 35 36 |
# File 'lib/prometheus/client/metric.rb', line 32 def get(labels = {}) @validator.valid?(labels) @values[labels] end |
#type ⇒ Object
Returns the metric type
27 28 29 |
# File 'lib/prometheus/client/metric.rb', line 27 def type fail NotImplementedError end |
#values ⇒ Object
Returns all label sets with their values
39 40 41 42 43 44 45 |
# File 'lib/prometheus/client/metric.rb', line 39 def values synchronize do @values.each_with_object({}) do |(labels, value), memo| memo[labels] = value end end end |