Class: Prometheus::Client::Metric

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

Overview

Metric

Direct Known Subclasses

Counter, Gauge, 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



32
33
34
35
36
# File 'lib/prometheus/client/metric.rb', line 32

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

  @values[labels]
end

#typeObject

Returns the metric type



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

def type
  fail NotImplementedError
end

#valuesObject

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