2019-07-18 09:54:11 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Prometheus
|
|
|
|
module PidProvider
|
|
|
|
extend self
|
|
|
|
|
|
|
|
def worker_id
|
|
|
|
if Sidekiq.server?
|
|
|
|
'sidekiq'
|
|
|
|
elsif defined?(Unicorn::Worker)
|
2019-07-26 11:02:21 -04:00
|
|
|
unicorn_worker_id
|
2019-07-18 09:54:11 -04:00
|
|
|
elsif defined?(::Puma)
|
2019-07-26 11:02:21 -04:00
|
|
|
puma_worker_id
|
2019-07-18 09:54:11 -04:00
|
|
|
else
|
2019-07-26 11:02:21 -04:00
|
|
|
unknown_process_id
|
2019-07-18 09:54:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def unicorn_worker_id
|
2019-07-26 11:02:21 -04:00
|
|
|
if matches = process_name.match(/unicorn.*worker\[([0-9]+)\]/)
|
|
|
|
"unicorn_#{matches[1]}"
|
|
|
|
elsif process_name =~ /unicorn/
|
|
|
|
"unicorn_master"
|
|
|
|
else
|
|
|
|
unknown_process_id
|
|
|
|
end
|
2019-07-18 09:54:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def puma_worker_id
|
2019-07-26 11:02:21 -04:00
|
|
|
if matches = process_name.match(/puma.*cluster worker ([0-9]+):/)
|
|
|
|
"puma_#{matches[1]}"
|
|
|
|
elsif process_name =~ /puma/
|
|
|
|
"puma_master"
|
|
|
|
else
|
|
|
|
unknown_process_id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def unknown_process_id
|
|
|
|
"process_#{Process.pid}"
|
2019-07-18 09:54:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def process_name
|
|
|
|
$0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|