Class: GitLab::Exporter::Database::PgSequencesProber

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_exporter/database/pg_sequences.rb

Overview

The prober which is called when gathering metrics

Constant Summary collapse

METRIC_NAME =
"gitlab_pg_sequences".freeze
METRIC_KEYS =
%w[min_value max_value current_value].freeze

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of PgSequencesProber.



32
33
34
35
# File 'lib/gitlab_exporter/database/pg_sequences.rb', line 32

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

Instance Method Details

#probe_dbObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/gitlab_exporter/database/pg_sequences.rb', line 37

def probe_db
  result = @collector.run

  result.each do |fully_qualified_sequencename, sequence_info|
    METRIC_KEYS.each do |key|
      value = sequence_info.fetch(key).to_f
      tags = {
        schemaname: sequence_info.fetch("schemaname"),
        sequencename: sequence_info.fetch("sequencename"),
        fully_qualified_sequencename: fully_qualified_sequencename
      }

      @metrics.add("#{METRIC_NAME}_#{key}", value, **tags)
    end
  end

  self
rescue PG::ConnectionBad
  self
end