Class: PrometheusExporter::Instrumentation::SidekiqProcess
- Inherits:
-
PeriodicStats
- Object
- PeriodicStats
- PrometheusExporter::Instrumentation::SidekiqProcess
show all
- Defined in:
- lib/prometheus_exporter/instrumentation/sidekiq_process.rb
Class Method Summary
collapse
Instance Method Summary
collapse
started?, stop, worker_loop
Constructor Details
Returns a new instance of SidekiqProcess.
16
17
18
19
|
# File 'lib/prometheus_exporter/instrumentation/sidekiq_process.rb', line 16
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
13
14
|
# 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 do
client.send_json(sidekiq_process_collector.collect)
end
super
end
|
Instance Method Details
#collect ⇒ Object
21
22
23
24
25
26
|
# File 'lib/prometheus_exporter/instrumentation/sidekiq_process.rb', line 21
def collect
{
type: 'sidekiq_process',
process: collect_stats
}
end
|
#collect_stats ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/prometheus_exporter/instrumentation/sidekiq_process.rb', line 28
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_process ⇒ Object
46
47
48
49
50
|
# File 'lib/prometheus_exporter/instrumentation/sidekiq_process.rb', line 46
def current_process
::Sidekiq::ProcessSet.new.find do |sp|
sp['hostname'] == @hostname && sp['pid'] == @pid
end
end
|