Class: GitLab::Monitor::Database::RowCountProber

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

Overview

The prober which is called when gathering metrics

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RowCountProber.



139
140
141
142
143
144
145
# File 'lib/gitlab_monitor/database/row_count.rb', line 139

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

Instance Method Details

#probe_dbObject



147
148
149
150
151
152
153
154
155
156
# File 'lib/gitlab_monitor/database/row_count.rb', line 147

def probe_db
  results = @collector.run
  results.each do |key, value|
    @metrics.add("gitlab_database_rows", value.to_i, query_name: key.to_s)
  end

  self
rescue PG::ConnectionBad
  self
end

#write_to(target) ⇒ Object



158
159
160
# File 'lib/gitlab_monitor/database/row_count.rb', line 158

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