Class: Gitlab::Usage::Metrics::Instrumentations::TotalCountMetric

Inherits:
BaseMetric
  • Object
show all
Includes:
Gitlab::UsageDataCounters::RedisCounter
Defined in:
lib/gitlab/usage/metrics/instrumentations/total_count_metric.rb

Overview

Usage example

In metric YAML definition:

instrumentation_class: TotalCountMetric options:

event: commit_pushed

Constant Summary collapse

KEY_PREFIX =
"{event_counters}_"

Constants included from TimeFrame

TimeFrame::ALL_TIME_TIME_FRAME_NAME, TimeFrame::DEFAULT_TIMESTAMP_COLUMN, TimeFrame::SEVEN_DAYS_TIME_FRAME_NAME, TimeFrame::TWENTY_EIGHT_DAYS_TIME_FRAME_NAME

Constants included from Gitlab::Utils::UsageData

Gitlab::Utils::UsageData::DISTRIBUTED_HLL_FALLBACK, Gitlab::Utils::UsageData::FALLBACK, Gitlab::Utils::UsageData::HISTOGRAM_FALLBACK, Gitlab::Utils::UsageData::MAX_BUCKET_SIZE

Instance Attribute Summary

Attributes inherited from BaseMetric

#events, #options, #time_frame

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::UsageDataCounters::RedisCounter

#increment, #increment_by, #total_count

Methods inherited from BaseMetric

available?, #available?, #initialize, #instrumentation

Methods included from TimeFrame

#monthly_time_range, #monthly_time_range_db_params, #weekly_time_range, #weekly_time_range_db_params

Methods included from Gitlab::Utils::UsageData

#add, #add_metric, #alt_usage_data, #average, #count, #distinct_count, #estimate_batch_distinct_count, #histogram, #maximum_id, #measure_duration, #minimum_id, #redis_usage_data, #sum, #track_usage_event, #with_finished_at, #with_metadata, #with_prometheus_client

Constructor Details

This class inherits a constructor from Gitlab::Usage::Metrics::Instrumentations::BaseMetric

Class Method Details

.redis_key(event_name) ⇒ Object



20
21
22
# File 'lib/gitlab/usage/metrics/instrumentations/total_count_metric.rb', line 20

def self.redis_key(event_name)
  KEY_PREFIX + event_name
end

Instance Method Details

#valueObject



24
25
26
27
28
29
30
# File 'lib/gitlab/usage/metrics/instrumentations/total_count_metric.rb', line 24

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