diff options
author | Ryan Cobb <rcobb@gitlab.com> | 2019-04-18 21:40:00 +0300 |
---|---|---|
committer | Ryan Cobb <rcobb@gitlab.com> | 2019-04-18 22:46:56 +0300 |
commit | 4c248c05cbd1356199cc96775b68fbbde64d4d5d (patch) | |
tree | 2e6778f2cedce86fc265baa792911f88af63942c /lib/gitlab/metrics/samplers/unicorn_sampler.rb | |
parent | db70b877512e5cdeb262c060a1a4dff1cf999a45 (diff) |
Adds new metrics for unicorn monitoring
This adds new metrics for monitoring unicorn. These metrics include
process_cpu_seconds_total, process_start_time_seconds, process_max_fds,
and unicorn_workers.
Diffstat (limited to 'lib/gitlab/metrics/samplers/unicorn_sampler.rb')
-rw-r--r-- | lib/gitlab/metrics/samplers/unicorn_sampler.rb | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/lib/gitlab/metrics/samplers/unicorn_sampler.rb b/lib/gitlab/metrics/samplers/unicorn_sampler.rb index bec64e864b3..16a2ee9b9be 100644 --- a/lib/gitlab/metrics/samplers/unicorn_sampler.rb +++ b/lib/gitlab/metrics/samplers/unicorn_sampler.rb @@ -8,12 +8,19 @@ module Gitlab super(interval) end - def unicorn_active_connections - @unicorn_active_connections ||= ::Gitlab::Metrics.gauge(:unicorn_active_connections, 'Unicorn active connections', {}, :max) + def metrics + @metrics ||= init_metrics end - def unicorn_queued_connections - @unicorn_queued_connections ||= ::Gitlab::Metrics.gauge(:unicorn_queued_connections, 'Unicorn queued connections', {}, :max) + def init_metrics + { + unicorn_active_connections: ::Gitlab::Metrics.gauge(:unicorn_active_connections, 'Unicorn active connections', {}, :max), + unicorn_queued_connections: ::Gitlab::Metrics.gauge(:unicorn_queued_connections, 'Unicorn queued connections', {}, :max), + unicorn_workers: ::Gitlab::Metrics.gauge(:unicorn_workers, 'Unicorn workers'), + process_cpu_seconds_total: ::Gitlab::Metrics.gauge(:process_cpu_seconds_total, 'Process CPU seconds total'), + process_max_fds: ::Gitlab::Metrics.gauge(:process_max_fds, 'Process max fds'), + process_start_time_seconds: ::Gitlab::Metrics.gauge(:process_start_time_seconds, 'Process start time seconds') + } end def enabled? @@ -23,14 +30,19 @@ module Gitlab def sample Raindrops::Linux.tcp_listener_stats(tcp_listeners).each do |addr, stats| - unicorn_active_connections.set({ socket_type: 'tcp', socket_address: addr }, stats.active) - unicorn_queued_connections.set({ socket_type: 'tcp', socket_address: addr }, stats.queued) + metrics[:unicorn_active_connections].set({ socket_type: 'tcp', socket_address: addr }, stats.active) + metrics[:unicorn_queued_connections].set({ socket_type: 'tcp', socket_address: addr }, stats.queued) end Raindrops::Linux.unix_listener_stats(unix_listeners).each do |addr, stats| - unicorn_active_connections.set({ socket_type: 'unix', socket_address: addr }, stats.active) - unicorn_queued_connections.set({ socket_type: 'unix', socket_address: addr }, stats.queued) + metrics[:unicorn_active_connections].set({ socket_type: 'unix', socket_address: addr }, stats.active) + metrics[:unicorn_queued_connections].set({ socket_type: 'unix', socket_address: addr }, stats.queued) end + + metrics[:process_cpu_seconds_total].set({ pid: nil }, ::Gitlab::Metrics::System.cpu_time) + metrics[:process_start_time_seconds].set({ pid: nil }, ::Gitlab::Metrics::System.process_start_time) + metrics[:process_max_fds].set({ pid: nil }, ::Gitlab::Metrics::System.max_open_file_descriptors) + metrics[:unicorn_workers].set({}, unicorn_workers_count) end private @@ -39,6 +51,10 @@ module Gitlab @tcp_listeners ||= Unicorn.listener_names.grep(%r{\A[^/]+:\d+\z}) end + def pid + @pid ||= Process.pid + end + def unix_listeners @unix_listeners ||= Unicorn.listener_names - tcp_listeners end @@ -46,6 +62,10 @@ module Gitlab def unicorn_with_listeners? defined?(Unicorn) && Unicorn.listener_names.any? end + + def unicorn_workers_count + Sys::ProcTable.ps.select {|p| p.cmdline.match(/unicorn_rails worker/)}.count + end end end end |