Class: RedisPrometheus::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_prometheus/collector.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCollector

Returns a new instance of Collector.



8
9
10
# File 'lib/redis_prometheus/collector.rb', line 8

def initialize
  @collectors = []
end

Class Method Details

.currentObject



3
4
5
6
# File 'lib/redis_prometheus/collector.rb', line 3

def self.current
  @current ||= self.new
  @current
end

Instance Method Details

#register(&block) ⇒ Object



24
25
26
# File 'lib/redis_prometheus/collector.rb', line 24

def register(&block)
  @collectors << block
end

#statsObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/redis_prometheus/collector.rb', line 12

def stats
  out = ""
  @collectors.each do |collector|
    ret = collector.call
    out << "# TYPE #{ret[:label]} #{ret[:type]}\n"
    out << "# HELP #{ret[:label]} #{ret[:description]}.\n"

    out << "#{ret[:label]}{service=\"#{ENV["REDIS_PROMETHEUS_SERVICE"]}\"} #{ret[:data]}\n"
  end
  out
end