Class: GitLab::Monitor::CLI::DatabaseTupleStats

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_monitor/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.


85
86
87
88
89
90
91
# File 'lib/gitlab_monitor/cli.rb', line 85

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


102
103
104
# File 'lib/gitlab_monitor/cli.rb', line 102

def help
  @options.help
end

#options(args) ⇒ Object


93
94
95
96
97
98
99
100
# File 'lib/gitlab_monitor/cli.rb', line 93

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


106
107
108
109
110
111
112
# File 'lib/gitlab_monitor/cli.rb', line 106

def run
  validate!

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