Class: PromMultiProc::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/prom_multi_proc/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket:, metrics:, batch_size: 1, batch_timeout: 3, logger: nil, validate: false, prefix: "") ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/prom_multi_proc/base.rb', line 8

def initialize(socket:, metrics:, batch_size: 1, batch_timeout: 3, logger: nil, validate: false, prefix: "")
  @prefix = prefix
  @logger = logger || ::Logger.new(STDOUT)

  unless File.socket?(socket)
    @logger.warn("Socket does not exist: #{socket}")
  end

  @metric_objects = Concurrent::Map.new
  @writer = Writer.new(socket: socket, batch_size: batch_size, batch_timeout: batch_timeout, validate: validate)
  @multi_lock = Mutex.new

  specs = get_specs(metrics)
  process_specs!(specs)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/prom_multi_proc/base.rb', line 6

def logger
  @logger
end

#prefixObject (readonly)

Returns the value of attribute prefix.



6
7
8
# File 'lib/prom_multi_proc/base.rb', line 6

def prefix
  @prefix
end

#writerObject (readonly)

Returns the value of attribute writer.



6
7
8
# File 'lib/prom_multi_proc/base.rb', line 6

def writer
  @writer
end

Instance Method Details

#metric(name) ⇒ Object



24
25
26
# File 'lib/prom_multi_proc/base.rb', line 24

def metric(name)
  @metric_objects[name]
end

#metric?(name) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/prom_multi_proc/base.rb', line 28

def metric?(name)
  @metric_objects.key?(name)
end

#metricsObject



32
33
34
# File 'lib/prom_multi_proc/base.rb', line 32

def metrics
  @metric_objects.keys
end

#multiObject



36
37
38
39
40
41
42
43
44
# File 'lib/prom_multi_proc/base.rb', line 36

def multi
  return unless block_given?
  result = @multi_lock.synchronize do
    Proxy.new(self).tap do |proxy|
      yield(proxy)
    end
  end
  @writer.write_multi(result.multis)
end