Class: PrometheusExporter::Instrumentation::SidekiqProcess

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PeriodicStats

started?, stop, worker_loop

Constructor Details

#initializeSidekiqProcess

Returns a new instance of SidekiqProcess.



14
15
16
17
# File 'lib/prometheus_exporter/instrumentation/sidekiq_process.rb', line 14

def initialize
  @pid = ::Process.pid
  @hostname = Socket.gethostname
end

Class Method Details

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



5
6
7
8
9
10
11
12
# File 'lib/prometheus_exporter/instrumentation/sidekiq_process.rb', line 5

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

  worker_loop { client.send_json(sidekiq_process_collector.collect) }

  super
end

Instance Method Details

#collectObject



19
20
21
# File 'lib/prometheus_exporter/instrumentation/sidekiq_process.rb', line 19

def collect
  { type: "sidekiq_process", process: collect_stats }
end

#collect_statsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/prometheus_exporter/instrumentation/sidekiq_process.rb', line 23

def collect_stats
  process = current_process
  return {} unless process

  {
    busy: process["busy"],
    concurrency: process["concurrency"],
    labels: {
      labels: process["labels"].sort.join(","),
      queues: process["queues"].sort.join(","),
      quiet: process["quiet"],
      tag: process["tag"],
      hostname: process["hostname"],
      identity: process["identity"],
    },
  }
end

#current_processObject



41
42
43
# File 'lib/prometheus_exporter/instrumentation/sidekiq_process.rb', line 41

def current_process
  ::Sidekiq::ProcessSet.new.find { |sp| sp["hostname"] == @hostname && sp["pid"] == @pid }
end