debian-mirror-gitlab/lib/gitlab/import/metrics.rb

56 lines
1.4 KiB
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
module Gitlab
module Import
2020-07-28 23:09:34 +05:30
class Metrics
IMPORT_DURATION_BUCKETS = [0.5, 1, 3, 5, 10, 60, 120, 240, 360, 720, 1440].freeze
2020-04-22 19:07:51 +05:30
2020-07-28 23:09:34 +05:30
attr_reader :importer
2020-04-22 19:07:51 +05:30
2020-07-28 23:09:34 +05:30
def initialize(importer, project)
@importer = importer
@project = project
end
def track_finished_import
duration = Time.zone.now - @project.created_at
duration_histogram.observe({ importer: importer }, duration)
projects_counter.increment
end
2020-04-22 19:07:51 +05:30
2020-07-28 23:09:34 +05:30
def projects_counter
@projects_counter ||= Gitlab::Metrics.counter(
:"#{importer}_imported_projects_total",
'The number of imported projects'
)
end
def issues_counter
@issues_counter ||= Gitlab::Metrics.counter(
:"#{importer}_imported_issues_total",
'The number of imported issues'
)
end
2020-04-22 19:07:51 +05:30
2020-07-28 23:09:34 +05:30
def merge_requests_counter
@merge_requests_counter ||= Gitlab::Metrics.counter(
:"#{importer}_imported_merge_requests_total",
'The number of imported merge (pull) requests'
)
2020-04-22 19:07:51 +05:30
end
2020-07-28 23:09:34 +05:30
private
def duration_histogram
@duration_histogram ||= Gitlab::Metrics.histogram(
:"#{importer}_total_duration_seconds",
'Total time spent importing projects, in seconds',
{},
IMPORT_DURATION_BUCKETS
)
2020-04-22 19:07:51 +05:30
end
end
end
end