Class: GitLab::Exporter::Database::RowCountProber

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_exporter/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.



209
210
211
212
213
214
215
# File 'lib/gitlab_exporter/database/row_count.rb', line 209

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



217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/gitlab_exporter/database/row_count.rb', line 217

def probe_db
  results = @collector.run
  results.each do |query_name, result|
    labels = { query_name: query_name.to_s }
    result.each do |row|
      @metrics.add("gitlab_database_rows", row[:count].to_f, **labels, **row[:labels])
    end
  end

  self
rescue PG::ConnectionBad
  self
end

#write_to(target) ⇒ Object



231
232
233
# File 'lib/gitlab_exporter/database/row_count.rb', line 231

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