Class: GitLab::Monitor::Database::TuplesProber

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

Overview

Probes the DB specified by opts for tuple stats, then converts them to metrics

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of TuplesProber.



28
29
30
31
# File 'lib/gitlab_monitor/database/tuple_stats.rb', line 28

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

Instance Method Details

#probe_dbObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gitlab_monitor/database/tuple_stats.rb', line 33

def probe_db
  result = @collector.run

  result.each do |table_name, tuple_stats|
    tuple_stats.each do |column_name, value|
      @metrics.add("gitlab_database_stat_table_#{column_name}", value.to_s, table_name: table_name)
    end
  end

  self
rescue PG::ConnectionBad
  self
end

#write_to(target) ⇒ Object



47
48
49
# File 'lib/gitlab_monitor/database/tuple_stats.rb', line 47

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