pghero 2.0.0 → 2.0.1
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 +4 -0
- data/README.md +2 -0
- data/app/controllers/pg_hero/home_controller.rb +4 -3
- data/app/views/pg_hero/home/relation_space.html.erb +6 -1
- data/app/views/pg_hero/home/space.html.erb +3 -3
- data/guides/Docker.md +22 -0
- data/guides/Linux.md +21 -0
- data/guides/Rails.md +21 -0
- data/lib/pghero/methods/space.rb +11 -8
- data/lib/pghero/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afbcdc4cdc3effd62204f1e0939797d86b04e315
|
4
|
+
data.tar.gz: 87a95863031e246f9d31663d09a400d1df392e7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b318e1fea0c1976440c4d7473b0c423dac92c945cbe18ddb755c4748e45b928d0b2ea86253a3b2830e6236e8314a592a5d78995477012218da91f75c9dd165b
|
7
|
+
data.tar.gz: 37c1d9495c3cf959c2cbb22244c268cb49872f0df72b343df30d9b0f6bd636e72fc1329441504596750458d394f4315e082071a53fbd5660a06bd35026904c35
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -6,6 +6,8 @@ A performance dashboard for Postgres - health checks, suggested indexes, and mor
|
|
6
6
|
|
7
7
|
[![Screenshot](https://pghero.dokkuapp.com/assets/screenshot-5a368624ada55b32e7668c96926840f9.png)](https://pghero.dokkuapp.com/)
|
8
8
|
|
9
|
+
PgHero 2.0 was just released! [Read details](https://medium.com/@ankane/pghero-2-0-has-arrived-266c3874d012).
|
10
|
+
|
9
11
|
:speech_balloon: Get [handcrafted updates](http://chartkick.us7.list-manage.com/subscribe?u=952c861f99eb43084e0a49f98&id=6ea6541e8e&group[0][16]=true) for new features
|
10
12
|
|
11
13
|
## Installation
|
@@ -67,10 +67,10 @@ module PgHero
|
|
67
67
|
@space_stats_enabled = @database.space_stats_enabled? && !params[:tables]
|
68
68
|
if @space_stats_enabled
|
69
69
|
space_growth = @database.space_growth(days: @days, relation_sizes: @relation_sizes)
|
70
|
-
@growth_bytes_by_relation = Hash[ space_growth.map { |r| [r[:relation], r[:growth_bytes]] } ]
|
70
|
+
@growth_bytes_by_relation = Hash[ space_growth.map { |r| [[r[:schema], r[:relation]], r[:growth_bytes]] } ]
|
71
71
|
case params[:sort]
|
72
72
|
when "growth"
|
73
|
-
@relation_sizes.sort_by! { |r| s = @growth_bytes_by_relation[r[:relation]]; [s ? 0 : 1, -s.to_i, r[:relation]] }
|
73
|
+
@relation_sizes.sort_by! { |r| s = @growth_bytes_by_relation[[r[:schema], r[:relation]]]; [s ? 0 : 1, -s.to_i, r[:schema], r[:relation]] }
|
74
74
|
when "name"
|
75
75
|
@relation_sizes.sort_by! { |r| r[:relation] || r[:table] }
|
76
76
|
end
|
@@ -84,9 +84,10 @@ module PgHero
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def relation_space
|
87
|
+
@schema = params[:schema] || "public"
|
87
88
|
@relation = params[:relation]
|
88
89
|
@title = @relation
|
89
|
-
relation_space_stats = @database.relation_space_stats(@relation)
|
90
|
+
relation_space_stats = @database.relation_space_stats(@relation, schema: @schema)
|
90
91
|
@chart_data = [{name: "Value", data: relation_space_stats.map { |r| [r[:captured_at], (r[:size_bytes].to_f / 1.megabyte).round(1)] }, library: chart_library_options}]
|
91
92
|
end
|
92
93
|
|
@@ -1,5 +1,10 @@
|
|
1
1
|
<div class="content">
|
2
|
-
<h1
|
2
|
+
<h1>
|
3
|
+
<%= @relation %>
|
4
|
+
<% if @schema != "public" %>
|
5
|
+
<small><%= @schema %></small>
|
6
|
+
<% end %>
|
7
|
+
</h1>
|
3
8
|
|
4
9
|
<h1>Size <small>MB</small></h1>
|
5
10
|
<div id="chart-1" class="chart" style="margin-bottom: 20px;">Loading...</div>
|
@@ -54,7 +54,7 @@ remove_index <%= query[:table].to_sym.inspect %>, name: <%= query[:index].to_s.i
|
|
54
54
|
<span style="word-break: break-all;">
|
55
55
|
<% name = query[:relation] || query[:table] %>
|
56
56
|
<% if @space_stats_enabled %>
|
57
|
-
<%= link_to name, relation_space_path(name), target: "_blank", style: "color: inherit;" %>
|
57
|
+
<%= link_to name, relation_space_path(name, schema: query[:schema]), target: "_blank", style: "color: inherit;" %>
|
58
58
|
<% else %>
|
59
59
|
<%= name %>
|
60
60
|
<% end %>
|
@@ -69,8 +69,8 @@ remove_index <%= query[:table].to_sym.inspect %>, name: <%= query[:index].to_s.i
|
|
69
69
|
<td><%= query[:size] %></td>
|
70
70
|
<% if @space_stats_enabled %>
|
71
71
|
<td>
|
72
|
-
<% if @growth_bytes_by_relation[query[:relation]] %>
|
73
|
-
<% if @growth_bytes_by_relation[query[:relation]] < 0 %>-<% end %><%= PgHero.pretty_size(@growth_bytes_by_relation[query[:relation]].abs) %>
|
72
|
+
<% if @growth_bytes_by_relation[[query[:schema], query[:relation]]] %>
|
73
|
+
<% if @growth_bytes_by_relation[[query[:schema], query[:relation]]] < 0 %>-<% end %><%= PgHero.pretty_size(@growth_bytes_by_relation[[query[:schema], query[:relation]]].abs) %>
|
74
74
|
<% else %>
|
75
75
|
<span class="text-muted">Unknown</span>
|
76
76
|
<% end %>
|
data/guides/Docker.md
CHANGED
@@ -38,6 +38,28 @@ docker run -ti -e DATABASE_URL=... ankane/pghero bin/rake pghero:capture_query_s
|
|
38
38
|
|
39
39
|
After this, a time range slider will appear on the Queries tab.
|
40
40
|
|
41
|
+
## Historical Space Stats
|
42
|
+
|
43
|
+
To track space stats over time, create a table to store them.
|
44
|
+
|
45
|
+
```sql
|
46
|
+
CREATE TABLE "pghero_space_stats" (
|
47
|
+
"id" serial primary key,
|
48
|
+
"database" text,
|
49
|
+
"schema" text,
|
50
|
+
"relation" text,
|
51
|
+
"size" bigint,
|
52
|
+
"captured_at" timestamp
|
53
|
+
)
|
54
|
+
CREATE INDEX ON "pghero_space_stats" ("database", "captured_at")
|
55
|
+
```
|
56
|
+
|
57
|
+
Schedule the task below to run once a day.
|
58
|
+
|
59
|
+
```sh
|
60
|
+
docker run -ti -e DATABASE_URL=... ankane/pghero bin/rake pghero:capture_space_stats
|
61
|
+
```
|
62
|
+
|
41
63
|
## Credits
|
42
64
|
|
43
65
|
Thanks to [Brian Morton](https://github.com/bmorton) for the [original Docker image](https://github.com/bmorton/pghero_solo).
|
data/guides/Linux.md
CHANGED
@@ -176,6 +176,27 @@ sudo pghero run rake pghero:capture_query_stats
|
|
176
176
|
|
177
177
|
After this, a time range slider will appear on the Queries tab.
|
178
178
|
|
179
|
+
## Historical Space Stats
|
180
|
+
|
181
|
+
To track space stats over time, create a table to store them.
|
182
|
+
|
183
|
+
```sql
|
184
|
+
CREATE TABLE "pghero_space_stats" (
|
185
|
+
"id" serial primary key,
|
186
|
+
"database" text,
|
187
|
+
"schema" text,
|
188
|
+
"relation" text,
|
189
|
+
"size" bigint,
|
190
|
+
"captured_at" timestamp
|
191
|
+
)
|
192
|
+
CREATE INDEX ON "pghero_space_stats" ("database", "captured_at")
|
193
|
+
```
|
194
|
+
|
195
|
+
Schedule the task below to run once a day.
|
196
|
+
|
197
|
+
```sh
|
198
|
+
sudo pghero run rake pghero:capture_space_stats
|
199
|
+
|
179
200
|
## System Stats
|
180
201
|
|
181
202
|
CPU usage is available for Amazon RDS. Add these variables to your environment:
|
data/guides/Rails.md
CHANGED
@@ -76,6 +76,27 @@ By default, query stats are stored in your app’s database. Change this with:
|
|
76
76
|
ENV["PGHERO_STATS_DATABASE_URL"]
|
77
77
|
```
|
78
78
|
|
79
|
+
## Historical Space Stats
|
80
|
+
|
81
|
+
To track space stats over time, run:
|
82
|
+
|
83
|
+
```sh
|
84
|
+
rails generate pghero:space_stats
|
85
|
+
rake db:migrate
|
86
|
+
```
|
87
|
+
|
88
|
+
And schedule the task below to run once a day.
|
89
|
+
|
90
|
+
```sh
|
91
|
+
rake pghero:capture_space_stats
|
92
|
+
```
|
93
|
+
|
94
|
+
Or with a scheduler like Clockwork, use:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
PgHero.capture_space_stats
|
98
|
+
```
|
99
|
+
|
79
100
|
## System Stats
|
80
101
|
|
81
102
|
CPU usage, IOPS, and other stats are available for Amazon RDS. Add these lines to your application’s Gemfile:
|
data/lib/pghero/methods/space.rb
CHANGED
@@ -49,12 +49,13 @@ module PgHero
|
|
49
49
|
def space_growth(days: 7, relation_sizes: nil)
|
50
50
|
if space_stats_enabled?
|
51
51
|
relation_sizes ||= self.relation_sizes
|
52
|
-
sizes = Hash[ relation_sizes.map { |r| [r[:relation], r[:size_bytes]] } ]
|
52
|
+
sizes = Hash[ relation_sizes.map { |r| [[r[:schema], r[:relation]], r[:size_bytes]] } ]
|
53
53
|
start_at = days.days.ago
|
54
54
|
|
55
55
|
stats = select_all_stats <<-SQL
|
56
56
|
WITH t AS (
|
57
57
|
SELECT
|
58
|
+
schema,
|
58
59
|
relation,
|
59
60
|
array_agg(size ORDER BY captured_at) AS sizes
|
60
61
|
FROM
|
@@ -63,19 +64,20 @@ module PgHero
|
|
63
64
|
database = #{quote(id)}
|
64
65
|
AND captured_at >= #{quote(start_at)}
|
65
66
|
GROUP BY
|
66
|
-
1
|
67
|
+
1, 2
|
67
68
|
)
|
68
69
|
SELECT
|
70
|
+
schema,
|
69
71
|
relation,
|
70
72
|
sizes[1] AS size_bytes
|
71
73
|
FROM
|
72
74
|
t
|
73
75
|
ORDER BY
|
74
|
-
1
|
76
|
+
1, 2
|
75
77
|
SQL
|
76
78
|
|
77
79
|
stats.each do |r|
|
78
|
-
relation = r[:relation]
|
80
|
+
relation = [r[:schema], r[:relation]]
|
79
81
|
if sizes[relation]
|
80
82
|
r[:growth_bytes] = sizes[relation] - r[:size_bytes]
|
81
83
|
end
|
@@ -87,10 +89,10 @@ module PgHero
|
|
87
89
|
end
|
88
90
|
end
|
89
91
|
|
90
|
-
def relation_space_stats(relation)
|
92
|
+
def relation_space_stats(relation, schema: "public")
|
91
93
|
if space_stats_enabled?
|
92
94
|
relation_sizes ||= self.relation_sizes
|
93
|
-
sizes = Hash[ relation_sizes.map { |r| [r[:relation], r[:size_bytes]] } ]
|
95
|
+
sizes = Hash[ relation_sizes.map { |r| [[r[:schema], r[:relation]], r[:size_bytes]] } ]
|
94
96
|
start_at = 30.days.ago
|
95
97
|
|
96
98
|
stats = select_all_stats <<-SQL
|
@@ -102,6 +104,7 @@ module PgHero
|
|
102
104
|
WHERE
|
103
105
|
database = #{quote(id)}
|
104
106
|
AND captured_at >= #{quote(start_at)}
|
107
|
+
AND schema = #{quote(schema)}
|
105
108
|
AND relation = #{quote(relation)}
|
106
109
|
ORDER BY
|
107
110
|
1 ASC
|
@@ -109,7 +112,7 @@ module PgHero
|
|
109
112
|
|
110
113
|
stats << {
|
111
114
|
captured_at: Time.now,
|
112
|
-
size_bytes: sizes[relation].to_i
|
115
|
+
size_bytes: sizes[[schema, relation]].to_i
|
113
116
|
}
|
114
117
|
else
|
115
118
|
raise NotEnabled, "Space stats not enabled"
|
@@ -121,7 +124,7 @@ module PgHero
|
|
121
124
|
columns = %w(database schema relation size captured_at)
|
122
125
|
values = []
|
123
126
|
relation_sizes.each do |rs|
|
124
|
-
values << [id, rs[:schema], rs[:
|
127
|
+
values << [id, rs[:schema], rs[:relation], rs[:size_bytes].to_i, now]
|
125
128
|
end
|
126
129
|
insert_stats("pghero_space_stats", columns, values)
|
127
130
|
end
|
data/lib/pghero/version.rb
CHANGED