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(metrics: PrometheusMetrics.new, **opts) ⇒ RowCountProber

Returns a new instance of RowCountProber.



234
235
236
237
# File 'lib/gitlab_exporter/database/row_count.rb', line 234

def initialize(metrics: PrometheusMetrics.new, **opts)
  @metrics = metrics
  @collector = RowCountCollector.new(**opts)
end

Instance Method Details

#probe_dbObject



239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/gitlab_exporter/database/row_count.rb', line 239

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



253
254
255
# File 'lib/gitlab_exporter/database/row_count.rb', line 253

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