Class: PrometheusExporter::Instrumentation::Unicorn

Inherits:
PeriodicStats
  • Object
show all
Defined in:
lib/prometheus_exporter/instrumentation/unicorn.rb

Overview

collects stats from unicorn

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PeriodicStats

started?, stop, worker_loop

Constructor Details

#initialize(pid_file:, listener_address:) ⇒ Unicorn

Returns a new instance of Unicorn.



24
25
26
27
28
# File 'lib/prometheus_exporter/instrumentation/unicorn.rb', line 24

def initialize(pid_file:, listener_address:)
  @pid_file = pid_file
  @listener_address = listener_address
  @tcp = listener_address =~ /\A.+:\d+\z/
end

Class Method Details

.start(pid_file:, listener_address:, client: nil, frequency: 30) ⇒ Object



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

def self.start(pid_file:, listener_address:, client: nil, frequency: 30)
  unicorn_collector = new(pid_file: pid_file, listener_address: listener_address)
  client ||= PrometheusExporter::Client.default

  worker_loop do
    metric = unicorn_collector.collect
    client.send_json metric
  end

  super
end

Instance Method Details

#collectObject



30
31
32
33
34
35
# File 'lib/prometheus_exporter/instrumentation/unicorn.rb', line 30

def collect
  metric = {}
  metric[:type] = "unicorn"
  collect_unicorn_stats(metric)
  metric
end

#collect_unicorn_stats(metric) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/prometheus_exporter/instrumentation/unicorn.rb', line 37

def collect_unicorn_stats(metric)
  stats = listener_address_stats

  metric[:active_workers] = stats.active
  metric[:request_backlog] = stats.queued
  metric[:workers] = worker_process_count
end