summaryrefslogtreecommitdiff
path: root/lib/gitlab/cluster/puma_worker_killer_observer.rb
blob: 3b4ebc3fbaec74cbab0d0bf48a77eae4000fb835 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

module Gitlab
  module Cluster
    class PumaWorkerKillerObserver
      def initialize
        @counter = Gitlab::Metrics.counter(:puma_killer_terminations_total, 'Number of workers terminated by PumaWorkerKiller')
      end

      # returns the Proc to be used as the observer callback block
      def callback
        method(:log_termination)
      end

      private

      def log_termination(worker)
        labels = { worker: "worker_#{worker.index}" }

        @counter.increment(labels)
      end
    end
  end
end