Class: Prometheus::Client::Registry

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

Overview

Registry

Defined Under Namespace

Classes: AlreadyRegisteredError

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



15
16
17
18
# File 'lib/prometheus/client/registry.rb', line 15

def initialize
  @metrics = {}
  @mutex = Mutex.new
end

Instance Method Details

#counter(name, docstring, base_labels = {}) ⇒ Object



34
35
36
# File 'lib/prometheus/client/registry.rb', line 34

def counter(name, docstring, base_labels = {})
  register(Counter.new(name, docstring, base_labels))
end

#exist?(name) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/prometheus/client/registry.rb', line 46

def exist?(name)
  @metrics.key?(name)
end

#gauge(name, docstring, base_labels = {}) ⇒ Object



42
43
44
# File 'lib/prometheus/client/registry.rb', line 42

def gauge(name, docstring, base_labels = {})
  register(Gauge.new(name, docstring, base_labels))
end

#get(name) ⇒ Object



50
51
52
# File 'lib/prometheus/client/registry.rb', line 50

def get(name)
  @metrics[name.to_sym]
end

#metricsObject



54
55
56
# File 'lib/prometheus/client/registry.rb', line 54

def metrics
  @metrics.values
end

#register(metric) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/prometheus/client/registry.rb', line 20

def register(metric)
  name = metric.name

  @mutex.synchronize do
    if exist?(name.to_sym)
      fail AlreadyRegisteredError, "#{name} has already been registered"
    else
      @metrics[name.to_sym] = metric
    end
  end

  metric
end

#summary(name, docstring, base_labels = {}) ⇒ Object



38
39
40
# File 'lib/prometheus/client/registry.rb', line 38

def summary(name, docstring, base_labels = {})
  register(Summary.new(name, docstring, base_labels))
end