Class: Prometheus::Client::Metric
- Inherits:
-
Object
- Object
- Prometheus::Client::Metric
- Defined in:
- lib/prometheus/client/metric.rb
Overview
Metric
Instance Attribute Summary collapse
-
#docstring ⇒ Object
readonly
Returns the value of attribute docstring.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#preset_labels ⇒ Object
readonly
Returns the value of attribute preset_labels.
Instance Method Summary collapse
-
#get(labels: {}) ⇒ Object
Returns the value for the given label set.
- #init_label_set(labels) ⇒ Object
-
#initialize(name, docstring:, labels: [], preset_labels: {}, store_settings: {}) ⇒ Metric
constructor
A new instance of Metric.
-
#values ⇒ Object
Returns all label sets with their values.
- #with_labels(labels) ⇒ Object
Constructor Details
#initialize(name, docstring:, labels: [], preset_labels: {}, store_settings: {}) ⇒ Metric
Returns a new instance of Metric.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/prometheus/client/metric.rb', line 12 def initialize(name, docstring:, labels: [], preset_labels: {}, store_settings: {}) validate_name(name) validate_docstring(docstring) @validator = LabelSetValidator.new(expected_labels: labels, reserved_labels: reserved_labels) @validator.validate_symbols!(labels) @validator.validate_symbols!(preset_labels) @labels = labels @store_settings = store_settings @name = name @docstring = docstring @preset_labels = stringify_values(preset_labels) @store = Prometheus::Client.config.data_store.for_metric( name, metric_type: type, metric_settings: store_settings ) if preset_labels.keys.length == labels.length @validator.validate_labelset!(preset_labels) @all_labels_preset = true end end |
Instance Attribute Details
#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 |
#preset_labels ⇒ Object (readonly)
Returns the value of attribute preset_labels.
10 11 12 |
# File 'lib/prometheus/client/metric.rb', line 10 def preset_labels @preset_labels end |
Instance Method Details
#get(labels: {}) ⇒ Object
Returns the value for the given label set
45 46 47 48 |
# File 'lib/prometheus/client/metric.rb', line 45 def get(labels: {}) label_set = label_set_for(labels) @store.get(labels: label_set) end |
#init_label_set(labels) ⇒ Object
58 59 60 |
# File 'lib/prometheus/client/metric.rb', line 58 def init_label_set(labels) @store.set(labels: label_set_for(labels), val: 0) end |
#values ⇒ Object
Returns all label sets with their values
63 64 65 |
# File 'lib/prometheus/client/metric.rb', line 63 def values @store.all_values end |
#with_labels(labels) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/prometheus/client/metric.rb', line 50 def with_labels(labels) self.class.new(name, docstring: docstring, labels: @labels, preset_labels: preset_labels.merge(labels), store_settings: @store_settings) end |