Class: Prometheus::Client::Metric
- Inherits:
-
Object
- Object
- Prometheus::Client::Metric
- Includes:
- UsesValueType
- Defined in:
- lib/prometheus/client/metric.rb
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.
-
#values ⇒ Object
Returns all label sets with their values.
Methods included from UsesValueType
Constructor Details
#initialize(name, docstring, base_labels = {}) ⇒ Metric
Returns a new instance of Metric.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/prometheus/client/metric.rb', line 11 def initialize(name, docstring, base_labels = {}) @mutex = Mutex.new @validator = case type when :summary LabelSetValidator.new(['quantile']) when :histogram LabelSetValidator.new(['le']) else LabelSetValidator.new end @values = Hash.new { |hash, key| hash[key] = default(key) } 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.
9 10 11 |
# File 'lib/prometheus/client/metric.rb', line 9 def base_labels @base_labels end |
#docstring ⇒ Object (readonly)
Returns the value of attribute docstring.
9 10 11 |
# File 'lib/prometheus/client/metric.rb', line 9 def docstring @docstring end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/prometheus/client/metric.rb', line 9 def name @name end |
Instance Method Details
#get(labels = {}) ⇒ Object
Returns the value for the given label set
33 34 35 36 37 38 |
# File 'lib/prometheus/client/metric.rb', line 33 def get(labels = {}) label_set = label_set_for(labels) @validator.valid?(label_set) @values[label_set].get end |
#values ⇒ Object
Returns all label sets with their values
41 42 43 44 45 46 47 |
# File 'lib/prometheus/client/metric.rb', line 41 def values synchronize do @values.each_with_object({}) do |(labels, value), memo| memo[labels] = value end end end |