Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2019-07-09 13:24:33 +0300
committerKamil Trzciński <ayufan@ayufan.eu>2019-07-09 17:06:15 +0300
commit580368c09b5f9f243b5ec8e271359d6a4ac8c398 (patch)
tree4f8c7d5fe8e3fe83b9785ed9f3aac082941aadf0 /lib
parent12422dbf10a1fca27b6f3c51224d3bb25ed173ed (diff)
Make unicorn_workers to return meaningful results
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/metrics/samplers/unicorn_sampler.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/gitlab/metrics/samplers/unicorn_sampler.rb b/lib/gitlab/metrics/samplers/unicorn_sampler.rb
index 9af7e0afed4..355f938704e 100644
--- a/lib/gitlab/metrics/samplers/unicorn_sampler.rb
+++ b/lib/gitlab/metrics/samplers/unicorn_sampler.rb
@@ -54,7 +54,16 @@ module Gitlab
end
def unicorn_workers_count
- `pgrep -f '[u]nicorn_rails worker.+ #{Rails.root.to_s}'`.split.count
+ http_servers.sum(&:worker_processes) # rubocop: disable CodeReuse/ActiveRecord
+ end
+
+ # Traversal of ObjectSpace is expensive, on fully loaded application
+ # it takes around 80ms. The instances of HttpServers are not a subject
+ # to change so we can cache the list of servers.
+ def http_servers
+ return [] unless defined?(::Unicorn::HttpServer)
+
+ @http_servers ||= ObjectSpace.each_object(::Unicorn::HttpServer).to_a
end
end
end