Class: Prometheus::Client::Metric

Inherits:
Object
  • Object
show all
Defined in:
lib/prometheus/client/metric.rb

Overview

Metric

Direct Known Subclasses

Counter, Gauge, Histogram, Summary

Instance Attribute Summary collapse

Instance Method Summary collapse

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_labelsObject (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

#docstringObject (readonly)

Returns the value of attribute docstring


10
11
12
# File 'lib/prometheus/client/metric.rb', line 10

def docstring
  @docstring
end

#nameObject (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


27
28
29
30
31
# File 'lib/prometheus/client/metric.rb', line 27

def get(labels = {})
  @validator.valid?(labels)

  @values[labels]
end

#valuesObject

Returns all label sets with their values


34
35
36
37
38
39
40
# File 'lib/prometheus/client/metric.rb', line 34

def values
  synchronize do
    @values.each_with_object({}) do |(labels, value), memo|
      memo[labels] = value
    end
  end
end