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/replica.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/suggested_indexes.rb,
app/controllers/pg_hero/home_controller.rb
Defined Under Namespace
Modules: Methods
Classes: Connection, Database, Engine, HomeController, QueryStats
Constant Summary
collapse
- VERSION =
"1.6.4"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.cache_hit_rate_threshold ⇒ Object
Returns the value of attribute cache_hit_rate_threshold.
31
32
33
|
# File 'lib/pghero.rb', line 31
def cache_hit_rate_threshold
@cache_hit_rate_threshold
end
|
.env ⇒ Object
Returns the value of attribute env.
31
32
33
|
# File 'lib/pghero.rb', line 31
def env
@env
end
|
.long_running_query_sec ⇒ Object
Returns the value of attribute long_running_query_sec.
31
32
33
|
# File 'lib/pghero.rb', line 31
def long_running_query_sec
@long_running_query_sec
end
|
.show_migrations ⇒ Object
Returns the value of attribute show_migrations.
31
32
33
|
# File 'lib/pghero.rb', line 31
def show_migrations
@show_migrations
end
|
.slow_query_calls ⇒ Object
Returns the value of attribute slow_query_calls.
31
32
33
|
# File 'lib/pghero.rb', line 31
def slow_query_calls
@slow_query_calls
end
|
.slow_query_ms ⇒ Object
Returns the value of attribute slow_query_ms.
31
32
33
|
# File 'lib/pghero.rb', line 31
def slow_query_ms
@slow_query_ms
end
|
.total_connections_threshold ⇒ Object
Returns the value of attribute total_connections_threshold.
31
32
33
|
# File 'lib/pghero.rb', line 31
def total_connections_threshold
@total_connections_threshold
end
|
Class Method Details
.capture_query_stats ⇒ Object
122
123
124
125
126
127
|
# File 'lib/pghero.rb', line 122
def capture_query_stats
databases.each do |_, database|
database.capture_query_stats
end
true
end
|
.capture_space_stats ⇒ Object
129
130
131
132
133
134
|
# File 'lib/pghero.rb', line 129
def capture_space_stats
databases.each do |_, database|
database.capture_space_stats
end
true
end
|
.config ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/pghero.rb', line 64
def config
Thread.current[:pghero_config] ||= begin
path = "config/pghero.yml"
config = YAML.load(ERB.new(File.read(path)).result) if File.exist?(path)
config ||= {}
if config[env]
config[env]
elsif config["databases"]
config
else
{
"databases" => {
"primary" => {
"url" => ENV["PGHERO_DATABASE_URL"] || ActiveRecord::Base.connection_config,
"db_instance_identifier" => ENV["PGHERO_DB_INSTANCE_IDENTIFIER"]
}
}
}
end
end
end
|
.current_database ⇒ Object
102
103
104
|
# File 'lib/pghero.rb', line 102
def current_database
Thread.current[:pghero_current_database] ||= primary_database
end
|
.current_database=(database) ⇒ Object
106
107
108
109
110
|
# File 'lib/pghero.rb', line 106
def current_database=(database)
raise "Database not found" unless databases[database.to_s]
Thread.current[:pghero_current_database] = databases[database.to_s]
database
end
|
.databases ⇒ Object
88
89
90
91
92
93
94
95
96
|
# File 'lib/pghero.rb', line 88
def databases
@databases ||= begin
Hash[
config["databases"].map do |id, c|
[id, PgHero::Database.new(id, c)]
end
]
end
end
|
.falsey?(value) ⇒ Boolean
141
142
143
|
# File 'lib/pghero.rb', line 141
def falsey?(value)
value == false || value == 'f'
end
|
.primary_database ⇒ Object
98
99
100
|
# File 'lib/pghero.rb', line 98
def primary_database
databases.values.first
end
|
.time_zone ⇒ Object
60
61
62
|
# File 'lib/pghero.rb', line 60
def time_zone
@time_zone || Time.zone
end
|
.time_zone=(time_zone) ⇒ Object
56
57
58
|
# File 'lib/pghero.rb', line 56
def time_zone=(time_zone)
@time_zone = time_zone.is_a?(ActiveSupport::TimeZone) ? time_zone : ActiveSupport::TimeZone[time_zone.to_s]
end
|
.truthy?(value) ⇒ Boolean
Handles Rails 4 (‘t’) and Rails 5 (true) values.
137
138
139
|
# File 'lib/pghero.rb', line 137
def truthy?(value)
value == true || value == 't'
end
|
.with(database) ⇒ Object
112
113
114
115
116
117
118
119
120
|
# File 'lib/pghero.rb', line 112
def with(database)
previous_database = current_database
begin
self.current_database = database
yield
ensure
self.current_database = previous_database.id
end
end
|