Class: GitLab::Exporter::CLI::DatabaseTupleStats

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

Overview

Database tuple stats runner.

It will take a database connection string and print results to STDOUT

Constant Summary collapse

COMMAND_NAME =
"db-tuple-stats".freeze

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ DatabaseTupleStats

Returns a new instance of DatabaseTupleStats.



100
101
102
103
104
105
106
# File 'lib/gitlab_exporter/cli.rb', line 100

def initialize(args)
  @options = options(args)
  @options.parse!

  @target = args.shift || STDOUT
  @target = File.open(@target, "a") if @target.is_a?(String)
end

Instance Method Details

#helpObject



117
118
119
# File 'lib/gitlab_exporter/cli.rb', line 117

def help
  @options.help
end

#options(args) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/gitlab_exporter/cli.rb', line 108

def options(args)
  args.options do |opts|
    opts.banner = "Usage: #{EXECUTABLE_NAME} #{COMMAND_NAME} [options]"
    opts.on("--db-conn=\"dbname=test port=5432\"", "Database connection string") do |val|
      @db_connection_string = val
    end
  end
end

#runObject



121
122
123
124
125
126
127
# File 'lib/gitlab_exporter/cli.rb', line 121

def run
  validate!

  ::GitLab::Exporter::Database::TuplesProber.new(connection_string: @db_connection_string)
                                            .probe_db
                                            .write_to(@target)
end