pghero 2.0.5 → 2.0.6
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of pghero might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/app/controllers/pg_hero/home_controller.rb +21 -1
- data/app/views/pg_hero/home/system.html.erb +1 -1
- data/guides/Rails.md +17 -0
- data/lib/pghero.rb +31 -12
- data/lib/pghero/methods/space.rb +1 -1
- data/lib/pghero/version.rb +1 -1
- data/lib/tasks/pghero.rake +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8c789e4669162dfec733b43ff6eb73f093671c3
|
4
|
+
data.tar.gz: 97992756ef94315ce617f324890f2357300b60e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b515756a401576febaeced7334e40dbdbd707f3f8e4405f7d33ba908bbdbbe0601234339e9e100cc7fa1087def73b7f5259a761314c33f2c8bd86a8191d6c84
|
7
|
+
data.tar.gz: 9f55d15a14dfe01b717c589e8a4948d5fbb541b50cd0b4132cc63fa692f2a50a70a01524c9b3b38fda365f18c5af842467e07b9f4b5dd7c0a5b4bd35e255cbeb
|
data/CHANGELOG.md
CHANGED
@@ -7,10 +7,12 @@ module PgHero
|
|
7
7
|
http_basic_authenticate_with name: ENV["PGHERO_USERNAME"], password: ENV["PGHERO_PASSWORD"] if ENV["PGHERO_PASSWORD"]
|
8
8
|
|
9
9
|
if respond_to?(:before_action)
|
10
|
+
before_action :check_api
|
10
11
|
before_action :set_database
|
11
12
|
before_action :set_query_stats_enabled
|
12
13
|
before_action :set_show_details, only: [:index, :queries, :show_query]
|
13
14
|
else
|
15
|
+
# no need to check API in earlier versions
|
14
16
|
before_filter :set_database
|
15
17
|
before_filter :set_query_stats_enabled
|
16
18
|
before_filter :set_show_details, only: [:index, :queries, :show_query]
|
@@ -179,7 +181,7 @@ module PgHero
|
|
179
181
|
@indexes_by_table = @database.indexes.group_by { |i| i[:table] }
|
180
182
|
end
|
181
183
|
else
|
182
|
-
|
184
|
+
render_text "Unknown query"
|
183
185
|
end
|
184
186
|
end
|
185
187
|
|
@@ -191,6 +193,12 @@ module PgHero
|
|
191
193
|
"1 week" => {duration: 1.week, period: 30.minutes},
|
192
194
|
"2 weeks" => {duration: 2.weeks, period: 1.hours}
|
193
195
|
}
|
196
|
+
@duration = (params[:duration] || 1.hour).to_i
|
197
|
+
@period = (params[:period] || 60.seconds).to_i
|
198
|
+
|
199
|
+
if @duration / @period > 1440
|
200
|
+
render_text "Too many data points"
|
201
|
+
end
|
194
202
|
end
|
195
203
|
|
196
204
|
def cpu_usage
|
@@ -364,5 +372,17 @@ module PgHero
|
|
364
372
|
end
|
365
373
|
top_connections.sort_by { |k, v| [-v, k] }
|
366
374
|
end
|
375
|
+
|
376
|
+
def check_api
|
377
|
+
render_text "No support for Rails API. See https://github.com/pghero/pghero for a standalone app." if Rails.application.config.try(:api_only)
|
378
|
+
end
|
379
|
+
|
380
|
+
def render_text(message)
|
381
|
+
if Rails::VERSION::MAJOR >= 5
|
382
|
+
render plain: message
|
383
|
+
else
|
384
|
+
render text: message
|
385
|
+
end
|
386
|
+
end
|
367
387
|
end
|
368
388
|
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<%= link_to name, system_path(options) %>
|
5
5
|
<% end %>
|
6
6
|
</p>
|
7
|
-
<% path_options = {duration:
|
7
|
+
<% path_options = {duration: @duration, period: @period} %>
|
8
8
|
|
9
9
|
<h1>CPU</h1>
|
10
10
|
<div id="chart-1" class="chart" style="margin-bottom: 20px;">Loading...</div>
|
data/guides/Rails.md
CHANGED
@@ -102,6 +102,8 @@ PgHero.capture_space_stats
|
|
102
102
|
CPU usage, IOPS, and other stats are available for Amazon RDS. Add these lines to your application’s Gemfile:
|
103
103
|
|
104
104
|
```ruby
|
105
|
+
gem 'aws-sdk-cloudwatch'
|
106
|
+
# or
|
105
107
|
gem 'aws-sdk'
|
106
108
|
```
|
107
109
|
|
@@ -113,6 +115,21 @@ PGHERO_SECRET_ACCESS_KEY=secret123
|
|
113
115
|
PGHERO_DB_INSTANCE_IDENTIFIER=epona
|
114
116
|
```
|
115
117
|
|
118
|
+
This requires the following IAM policy:
|
119
|
+
|
120
|
+
```json
|
121
|
+
{
|
122
|
+
"Version": "2012-10-17",
|
123
|
+
"Statement": [
|
124
|
+
{
|
125
|
+
"Effect": "Allow",
|
126
|
+
"Action": "cloudwatch:GetMetricStatistics",
|
127
|
+
"Resource": "*"
|
128
|
+
}
|
129
|
+
]
|
130
|
+
}
|
131
|
+
```
|
132
|
+
|
116
133
|
## Multiple Databases
|
117
134
|
|
118
135
|
Create `config/pghero.yml` with:
|
data/lib/pghero.rb
CHANGED
@@ -107,37 +107,56 @@ module PgHero
|
|
107
107
|
databases.values.first
|
108
108
|
end
|
109
109
|
|
110
|
-
def capture_query_stats
|
111
|
-
|
110
|
+
def capture_query_stats(verbose: false)
|
111
|
+
each_database do |database|
|
112
|
+
puts "Capturing query stats for #{database.id}..." if verbose
|
112
113
|
database.capture_query_stats
|
113
114
|
end
|
114
|
-
true
|
115
115
|
end
|
116
116
|
|
117
|
-
def capture_space_stats
|
118
|
-
|
117
|
+
def capture_space_stats(verbose: false)
|
118
|
+
each_database do |database|
|
119
|
+
puts "Capturing space stats for #{database.id}..." if verbose
|
119
120
|
database.capture_space_stats
|
120
121
|
end
|
121
|
-
true
|
122
122
|
end
|
123
123
|
|
124
124
|
def analyze_all(**options)
|
125
|
-
|
125
|
+
each_database do |database|
|
126
|
+
next if database.replica?
|
126
127
|
database.analyze_tables(**options)
|
127
128
|
end
|
128
|
-
true
|
129
129
|
end
|
130
130
|
|
131
|
-
def autoindex_all(create: false)
|
132
|
-
|
133
|
-
puts "Autoindexing #{database}..."
|
131
|
+
def autoindex_all(create: false, verbose: true)
|
132
|
+
each_database do |database|
|
133
|
+
puts "Autoindexing #{database}..." if verbose
|
134
134
|
database.autoindex(create: create)
|
135
135
|
end
|
136
|
-
true
|
137
136
|
end
|
138
137
|
|
139
138
|
def pretty_size(value)
|
140
139
|
ActiveSupport::NumberHelper.number_to_human_size(value, precision: 3)
|
141
140
|
end
|
141
|
+
|
142
|
+
private
|
143
|
+
|
144
|
+
def each_database
|
145
|
+
first_error = nil
|
146
|
+
|
147
|
+
databases.each do |_, database|
|
148
|
+
begin
|
149
|
+
yield database
|
150
|
+
rescue => e
|
151
|
+
puts "#{e.class.name}: #{e.message}"
|
152
|
+
puts
|
153
|
+
first_error ||= e
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
raise first_error if first_error
|
158
|
+
|
159
|
+
true
|
160
|
+
end
|
142
161
|
end
|
143
162
|
end
|
data/lib/pghero/methods/space.rb
CHANGED
@@ -126,7 +126,7 @@ module PgHero
|
|
126
126
|
relation_sizes.each do |rs|
|
127
127
|
values << [id, rs[:schema], rs[:relation], rs[:size_bytes].to_i, now]
|
128
128
|
end
|
129
|
-
insert_stats("pghero_space_stats", columns, values)
|
129
|
+
insert_stats("pghero_space_stats", columns, values) if values.any?
|
130
130
|
end
|
131
131
|
|
132
132
|
def space_stats_enabled?
|
data/lib/pghero/version.rb
CHANGED
data/lib/tasks/pghero.rake
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
namespace :pghero do
|
2
2
|
desc "capture query stats"
|
3
3
|
task capture_query_stats: :environment do
|
4
|
-
PgHero.capture_query_stats
|
4
|
+
PgHero.capture_query_stats(verbose: true)
|
5
5
|
end
|
6
6
|
|
7
7
|
desc "capture space stats"
|
8
8
|
task capture_space_stats: :environment do
|
9
|
-
PgHero.capture_space_stats
|
9
|
+
PgHero.capture_space_stats(verbose: true)
|
10
10
|
end
|
11
11
|
|
12
12
|
desc "analyze tables"
|
@@ -16,6 +16,6 @@ namespace :pghero do
|
|
16
16
|
|
17
17
|
desc "autoindex"
|
18
18
|
task autoindex: :environment do
|
19
|
-
PgHero.autoindex_all(create: true)
|
19
|
+
PgHero.autoindex_all(verbose: true, create: true)
|
20
20
|
end
|
21
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pghero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|