Class: Dexter::Client
- Inherits:
-
Object
- Object
- Dexter::Client
- Extended by:
- Logging
- Includes:
- Logging
- Defined in:
- lib/dexter/client.rb
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ Client
constructor
A new instance of Client.
- #parse_args(args) ⇒ Object
- #perform ⇒ Object
Methods included from Logging
Constructor Details
#initialize(args) ⇒ Client
Returns a new instance of Client.
14 15 16 |
# File 'lib/dexter/client.rb', line 14 def initialize(args) @arguments, @options = parse_args(args) end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
6 7 8 |
# File 'lib/dexter/client.rb', line 6 def arguments @arguments end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/dexter/client.rb', line 6 def @options end |
Class Method Details
Instance Method Details
#parse_args(args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/dexter/client.rb', line 44 def parse_args(args) opts = Slop.parse(args) do |o| o. = %(Usage: dexter [options]) o.separator "" o.separator "Input options:" o.string "--input-format", "input format" o.boolean "--pg-stat-activity", "use pg_stat_activity", default: false o.boolean "--pg-stat-statements", "use pg_stat_statements", default: false, help: false o.boolean "--stdin", "use stdin", default: false o.string "-s", "--statement", "process a single statement" o.separator "" o.separator "Connection options:" o.string "-d", "--dbname", "database name" o.string "-h", "--host", "database host" o.integer "-p", "--port", "database port" o.string "-U", "--username", "database user" o.separator "" o.separator "Processing options:" o.integer "--interval", "time to wait between processing queries, in seconds", default: 60 # TODO change to integer in 0.6.0 o.float "--min-calls", "only process queries that have been called a certain number of times", default: 0 o.float "--min-time", "only process queries that have consumed a certain amount of DB time, in minutes", default: 0 o.separator "" o.separator "Indexing options:" o.boolean "--analyze", "analyze tables that haven't been analyzed in the past hour", default: false o.boolean "--create", "create indexes", default: false o.boolean "--enable-hypopg", "enable the HypoPG extension", default: false o.array "--exclude", "prevent specific tables from being indexed" o.string "--include", "only include specific tables" o.integer "--min-cost-savings-pct", default: 50, help: false o.string "--tablespace", "tablespace to create indexes" o.separator "" o.separator "Logging options:" o.boolean "--log-explain", "log explain", default: false, help: false o.string "--log-level", "log level", default: "info" o.boolean "--log-sql", "log sql", default: false o.separator "" o.separator "Other options:" o.on "-v", "--version", "print the version" do log Dexter::VERSION exit end o.on "--help", "prints help" do log o exit end end arguments = opts.arguments = opts.to_hash [:dbname] = arguments.shift unless [:dbname] # TODO don't use global var $log_level = [:log_level].to_s.downcase raise Dexter::Abort, "Unknown log level" unless ["error", "info", "debug", "debug2", "debug3"].include?($log_level) [arguments, ] rescue Slop::Error => e raise Dexter::Abort, e. end |
#perform ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dexter/client.rb', line 18 def perform STDOUT.sync = true STDERR.sync = true if [:statement] query = Query.new([:statement]) Indexer.new().process_queries([query]) elsif [:pg_stat_statements] # TODO support streaming option Indexer.new().process_stat_statements elsif [:pg_stat_activity] Processor.new(:pg_stat_activity, ).perform elsif arguments.any? ARGV.replace(arguments) if ![:input_format] ext = ARGV.map { |v| File.extname(v) }.uniq [:input_format] = ext.first[1..-1] if ext.size == 1 end Processor.new(ARGF, ).perform elsif [:stdin] Processor.new(STDIN, ).perform else raise Dexter::Abort, "Specify a source of queries: --pg-stat-statements, --pg-stat-activity, --stdin, or a path" end end |