class GitLab::Monitor::Database::BloatProber

Prober class to gather bloat metrics

Constants

METRIC_KEYS

Attributes

bloat_types[R]
collector[R]
metrics[R]

Public Class Methods

new(opts, metrics: PrometheusMetrics.new, collector: BloatCollector.new(connection_string: opts[:connection_string])) click to toggle source
# File lib/gitlab_monitor/database/bloat.rb, line 40
def initialize(opts,
               metrics: PrometheusMetrics.new,
               collector: BloatCollector.new(connection_string: opts[:connection_string]))
  @metrics = metrics
  @collector = collector
  @bloat_types = opts[:bloat_types] || %i(btree table)
end

Public Instance Methods

probe_db() click to toggle source
# File lib/gitlab_monitor/database/bloat.rb, line 48
def probe_db
  bloat_types.each do |type|
    probe_for_type(type)
  end
end
write_to(target) click to toggle source
# File lib/gitlab_monitor/database/bloat.rb, line 54
def write_to(target)
  target.write(metrics.to_s)
end

Private Instance Methods

probe_for_type(type) click to toggle source
# File lib/gitlab_monitor/database/bloat.rb, line 60
def probe_for_type(type)
  collector.run(type).each do |query_name, data|
    METRIC_KEYS.each do |key|
      metrics.add("gitlab_database_bloat_#{type}_#{key}", data[key], query_name: query_name)
    end
  end

  self
rescue PG::ConnectionBad
  self
end