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.



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

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

Instance Method Details

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



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

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

#exist?(name) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/prometheus/client/registry.rb', line 52

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

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



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

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

#get(name) ⇒ Object



56
57
58
# File 'lib/prometheus/client/registry.rb', line 56

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

#histogram(name, docstring, base_labels = {}, buckets = Histogram::DEFAULT_BUCKETS) ⇒ Object



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

def histogram(name, docstring, base_labels = {},
              buckets = Histogram::DEFAULT_BUCKETS)
  register(Histogram.new(name, docstring, base_labels, buckets))
end

#metricsObject



60
61
62
# File 'lib/prometheus/client/registry.rb', line 60

def metrics
  @metrics.values
end

#register(metric) ⇒ Object



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

def register(metric)
  name = metric.name

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

  metric
end

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



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

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