Class: Prometheus::Client::Metric

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

Overview

Metric

Direct Known Subclasses

Counter, Gauge, Histogram

Instance Method Summary collapse

Constructor Details

#initializeMetric

Returns a new instance of Metric.



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

def initialize
  @mutex = Mutex.new
  @values = Hash.new(default)
end

Instance Method Details

#defaultObject

Default value



14
15
16
# File 'lib/prometheus/client/metric.rb', line 14

def default
  nil
end

#get(labels = {}) ⇒ Object

Returns the value for the given label set



31
32
33
# File 'lib/prometheus/client/metric.rb', line 31

def get(labels = {})
  @values[label_set_for(labels)]
end

#set(labels, value) ⇒ Object

Sets the value for the given label set



36
37
38
# File 'lib/prometheus/client/metric.rb', line 36

def set(labels, value)
  @values[label_set_for(labels)] = value
end

#to_json(*json) ⇒ Object

Generates JSON representation



41
42
43
44
45
46
# File 'lib/prometheus/client/metric.rb', line 41

def to_json(*json)
  {
    'type' => type,
    'value' => value
  }.to_json(*json)
end

#typeObject

Returns the metric type

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/prometheus/client/metric.rb', line 19

def type
  raise NotImplementedError
end

#valueObject

Returns all values



24
25
26
27
28
# File 'lib/prometheus/client/metric.rb', line 24

def value
  @values.map do |labels, value|
    { :labels => labels, :value => value }
  end
end