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

total_count_metric.rb « instrumentations « metrics « usage « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d07438f4bf7d63e9b7f441561fbbf3b3fbb61f59 (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
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

module Gitlab
  module Usage
    module Metrics
      module Instrumentations
        # Usage example
        #
        # In metric YAML definition:
        #
        # instrumentation_class: TotalCountMetric
        # options:
        #   event: commit_pushed
        #
        class TotalCountMetric < BaseMetric
          include Gitlab::UsageDataCounters::RedisCounter

          KEY_PREFIX = "{event_counters}_"

          def self.redis_key(event_name)
            KEY_PREFIX + event_name
          end

          def value
            events.sum do |event|
              redis_usage_data do
                total_count(self.class.redis_key(event[:name]))
              end
            end
          end
        end
      end
    end
  end
end