Module: PgHero

Extended by:
Forwardable
Defined in:
lib/pghero.rb,
lib/pghero/engine.rb,
lib/pghero/version.rb,
lib/pghero/database.rb,
lib/pghero/connection.rb,
lib/pghero/query_stats.rb,
lib/pghero/methods/kill.rb,
lib/pghero/methods/basic.rb,
lib/pghero/methods/space.rb,
lib/pghero/methods/users.rb,
lib/pghero/methods/system.rb,
lib/pghero/methods/tables.rb,
lib/pghero/methods/explain.rb,
lib/pghero/methods/indexes.rb,
lib/pghero/methods/queries.rb,
lib/pghero/methods/settings.rb,
lib/pghero/methods/sequences.rb,
lib/pghero/methods/connections.rb,
lib/pghero/methods/maintenance.rb,
lib/pghero/methods/query_stats.rb,
lib/pghero/methods/replication.rb,
app/helpers/pg_hero/base_helper.rb,
lib/pghero/methods/suggested_indexes.rb,
app/controllers/pg_hero/home_controller.rb

Defined Under Namespace

Modules: BaseHelper, Methods Classes: Connection, Database, Engine, Error, HomeController, NotEnabled, QueryStats

Constant Summary collapse

VERSION =
"2.2.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cache_hit_rate_thresholdObject

Returns the value of attribute cache_hit_rate_threshold.



35
36
37
# File 'lib/pghero.rb', line 35

def cache_hit_rate_threshold
  @cache_hit_rate_threshold
end

.envObject

Returns the value of attribute env.



35
36
37
# File 'lib/pghero.rb', line 35

def env
  @env
end

.explain_timeout_secObject

Returns the value of attribute explain_timeout_sec.



35
36
37
# File 'lib/pghero.rb', line 35

def explain_timeout_sec
  @explain_timeout_sec
end

.long_running_query_secObject

Returns the value of attribute long_running_query_sec.



35
36
37
# File 'lib/pghero.rb', line 35

def long_running_query_sec
  @long_running_query_sec
end

.show_migrationsObject

Returns the value of attribute show_migrations.



35
36
37
# File 'lib/pghero.rb', line 35

def show_migrations
  @show_migrations
end

.slow_query_callsObject

Returns the value of attribute slow_query_calls.



35
36
37
# File 'lib/pghero.rb', line 35

def slow_query_calls
  @slow_query_calls
end

.slow_query_msObject

Returns the value of attribute slow_query_ms.



35
36
37
# File 'lib/pghero.rb', line 35

def slow_query_ms
  @slow_query_ms
end

.total_connections_thresholdObject

Returns the value of attribute total_connections_threshold.



35
36
37
# File 'lib/pghero.rb', line 35

def total_connections_threshold
  @total_connections_threshold
end

Class Method Details

.analyze_all(**options) ⇒ Object



126
127
128
129
130
131
# File 'lib/pghero.rb', line 126

def analyze_all(**options)
  each_database do |database|
    next if database.replica?
    database.analyze_tables(**options)
  end
end

.autoindex_all(create: false, verbose: true) ⇒ Object



133
134
135
136
137
138
# File 'lib/pghero.rb', line 133

def autoindex_all(create: false, verbose: true)
  each_database do |database|
    puts "Autoindexing #{database}..." if verbose
    database.autoindex(create: create)
  end
end

.capture_query_stats(verbose: false) ⇒ Object



111
112
113
114
115
116
117
# File 'lib/pghero.rb', line 111

def capture_query_stats(verbose: false)
  each_database do |database|
    next unless database.capture_query_stats?
    puts "Capturing query stats for #{database.id}..." if verbose
    database.capture_query_stats(raise_errors: true)
  end
end

.capture_space_stats(verbose: false) ⇒ Object



119
120
121
122
123
124
# File 'lib/pghero.rb', line 119

def capture_space_stats(verbose: false)
  each_database do |database|
    puts "Capturing space stats for #{database.id}..." if verbose
    database.capture_space_stats
  end
end

.configObject



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
# File 'lib/pghero.rb', line 69

def config
  @config ||= begin
    path = "config/pghero.yml"

    config_file_exists = File.exist?(path)

    config = YAML.load(ERB.new(File.read(path)).result) if config_file_exists
    config ||= {}

    if config[env]
      config[env]
    elsif config["databases"] # preferred format
      config
    elsif config_file_exists
      raise "Invalid config file"
    else
      {
        "databases" => {
          "primary" => {
            "url" => ENV["PGHERO_DATABASE_URL"] || ActiveRecord::Base.connection_config,
            "db_instance_identifier" => ENV["PGHERO_DB_INSTANCE_IDENTIFIER"]
          }
        }
      }
    end
  end
end

.databasesObject



97
98
99
100
101
102
103
104
105
# File 'lib/pghero.rb', line 97

def databases
  @databases ||= begin
    Hash[
      config["databases"].map do |id, c|
        [id.to_sym, PgHero::Database.new(id, c)]
      end
    ]
  end
end

.pretty_size(value) ⇒ Object



140
141
142
# File 'lib/pghero.rb', line 140

def pretty_size(value)
  ActiveSupport::NumberHelper.number_to_human_size(value, precision: 3)
end

.primary_databaseObject



107
108
109
# File 'lib/pghero.rb', line 107

def primary_database
  databases.values.first
end

.time_zoneObject



65
66
67
# File 'lib/pghero.rb', line 65

def time_zone
  @time_zone || Time.zone
end

.time_zone=(time_zone) ⇒ Object



61
62
63
# File 'lib/pghero.rb', line 61

def time_zone=(time_zone)
  @time_zone = time_zone.is_a?(ActiveSupport::TimeZone) ? time_zone : ActiveSupport::TimeZone[time_zone.to_s]
end