Class: GitLab::Monitor::Database::RemoteMirrorsProber

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_monitor/database/remote_mirrors.rb

Overview

The prober which is called when gathering metrics

Instance Method Summary collapse

Constructor Details

#initialize(opts, metrics: PrometheusMetrics.new) ⇒ RemoteMirrorsProber

Returns a new instance of RemoteMirrorsProber.


38
39
40
41
42
43
44
# File 'lib/gitlab_monitor/database/remote_mirrors.rb', line 38

def initialize(opts, metrics: PrometheusMetrics.new)
  @metrics = metrics
  @collector = RemoteMirrorsCollector.new(
    connection_string: opts[:connection_string],
    project_ids: opts[:project_ids]
  )
end

Instance Method Details

#probe_dbObject

rubocop:disable Metrics/MethodLength


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/gitlab_monitor/database/remote_mirrors.rb', line 46

def probe_db # rubocop:disable Metrics/MethodLength
  results = @collector.run
  results.to_a.each do |row|
    @metrics.add(
      "project_remote_mirror_last_successful_update_time_seconds",
      row["last_successful_update_at"].to_i,
      project_id: row["project_id"],
      url: row["url"]
    )
    @metrics.add(
      "project_remote_mirror_last_update_time_seconds",
      row["last_update_at"].to_i,
      project_id: row["project_id"],
      url: row["url"]
    )
  end

  self
rescue PG::ConnectionBad
  self
end

#write_to(target) ⇒ Object


68
69
70
# File 'lib/gitlab_monitor/database/remote_mirrors.rb', line 68

def write_to(target)
  target.write(@metrics.to_s)
end