postgres-vacuum-monitor 0.10.1 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +83 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +3 -0
- data/Appraisals +10 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile +2 -0
- data/README.md +1 -1
- data/Rakefile +2 -0
- data/bin/console +4 -3
- data/gemfiles/activerecord_5_2.gemfile +10 -0
- data/gemfiles/activerecord_6_0.gemfile +10 -0
- data/gemfiles/activerecord_6_1.gemfile +10 -0
- data/lib/postgres/vacuum/compatibility.rb +15 -0
- data/lib/postgres/vacuum/configuration.rb +2 -0
- data/lib/postgres/vacuum/jobs/monitor_job.rb +22 -8
- data/lib/postgres/vacuum/monitor.rb +4 -1
- data/lib/postgres/vacuum/monitor/query.rb +11 -9
- data/lib/postgres/vacuum/monitor/version.rb +3 -1
- data/postgres-vacuum-monitor.gemspec +6 -4
- metadata +27 -17
- data/.travis.yml +0 -14
- data/gemfiles/activerecord_5.gemfile +0 -7
- data/gemfiles/activerecord_6.gemfile +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c398c3078e1b811e2f20aa747a7163089a18983b27a0f8717bbf0b31c3d6168
|
4
|
+
data.tar.gz: b1fd3ddf77ae9486cf3ed321d47485a69d7f2d6cf219a9281edc33a4defbd3ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c622be7d73d1ffe0232b98e05268aec917681b39e703f5fc82d1fab39faf2117669654e982bf6a04ac12849e2f6b18d33a8d6e98256f4bcaf7afa2d2244471f
|
7
|
+
data.tar.gz: cc422931d00b068cd17354f8fb74dafea4e31bd1fb0a1db94f5c769f505ad8fa14a8a94b681ddb14521336ea2b21b4a10c20cd9e1c1060861e803a1a6a20093e
|
@@ -0,0 +1,83 @@
|
|
1
|
+
version: 2.1
|
2
|
+
jobs:
|
3
|
+
lint:
|
4
|
+
docker:
|
5
|
+
- image: salsify/ruby_ci:2.5.8
|
6
|
+
working_directory: ~/postgres-vacuum-monitor
|
7
|
+
steps:
|
8
|
+
- checkout
|
9
|
+
- restore_cache:
|
10
|
+
keys:
|
11
|
+
- v1-gems-ruby-2.5.8-{{ checksum "postgres-vacuum-monitor.gemspec" }}-{{ checksum "Gemfile" }}
|
12
|
+
- v1-gems-ruby-2.5.8-
|
13
|
+
- run:
|
14
|
+
name: Install Gems
|
15
|
+
command: |
|
16
|
+
if ! bundle check --path=vendor/bundle; then
|
17
|
+
bundle install --path=vendor/bundle --jobs=4 --retry=3
|
18
|
+
bundle clean
|
19
|
+
fi
|
20
|
+
- save_cache:
|
21
|
+
key: v1-gems-ruby-2.5.8-{{ checksum "postgres-vacuum-monitor.gemspec" }}-{{ checksum "Gemfile" }}
|
22
|
+
paths:
|
23
|
+
- "vendor/bundle"
|
24
|
+
- "gemfiles/vendor/bundle"
|
25
|
+
- run:
|
26
|
+
name: Run Rubocop
|
27
|
+
command: bundle exec rubocop --config .rubocop.yml
|
28
|
+
test:
|
29
|
+
parameters:
|
30
|
+
gemfile:
|
31
|
+
type: string
|
32
|
+
docker:
|
33
|
+
- image: salsify/ruby_ci:2.5.8
|
34
|
+
environment:
|
35
|
+
TEST_DATABASE_URL: postgresql://circleci@localhost/circle_test
|
36
|
+
- image: circleci/postgres:9.6
|
37
|
+
environment:
|
38
|
+
POSTGRES_USER: "ubuntu"
|
39
|
+
POSTGRES_DB: "postgres_vacuum_monitor_test"
|
40
|
+
POSTGRES_HOST_AUTH_METHOD: "trust"
|
41
|
+
environment:
|
42
|
+
RACK_ENV: "test"
|
43
|
+
DB_HOST: 'localhost'
|
44
|
+
DB_USER: 'ubuntu'
|
45
|
+
RAILS_ENV: "test"
|
46
|
+
CIRCLE_TEST_REPORTS: "test-results"
|
47
|
+
BUNDLE_GEMFILE: << parameters.gemfile >>
|
48
|
+
working_directory: ~/postgres-vacuum-monitor
|
49
|
+
steps:
|
50
|
+
- checkout
|
51
|
+
- restore_cache:
|
52
|
+
keys:
|
53
|
+
- v1-gems-ruby-2.5.8-{{ checksum "postgres-vacuum-monitor.gemspec" }}-{{ checksum "<< parameters.gemfile >>" }}
|
54
|
+
- v1-gems-ruby-2.5.8-
|
55
|
+
- run:
|
56
|
+
name: Install Gems
|
57
|
+
command: |
|
58
|
+
if ! bundle check --path=vendor/bundle; then
|
59
|
+
bundle install --path=vendor/bundle --jobs=4 --retry=3
|
60
|
+
bundle clean
|
61
|
+
fi
|
62
|
+
- save_cache:
|
63
|
+
key: v1-gems-ruby-2.5.8-{{ checksum "postgres-vacuum-monitor.gemspec" }}-{{ checksum "<< parameters.gemfile >>" }}
|
64
|
+
paths:
|
65
|
+
- "vendor/bundle"
|
66
|
+
- "gemfiles/vendor/bundle"
|
67
|
+
- run:
|
68
|
+
name: Run Tests
|
69
|
+
command: |
|
70
|
+
bundle exec rspec --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/rspec/junit.xml --format progress spec
|
71
|
+
- store_test_results:
|
72
|
+
path: "test-results"
|
73
|
+
workflows:
|
74
|
+
build:
|
75
|
+
jobs:
|
76
|
+
- lint
|
77
|
+
- test:
|
78
|
+
matrix:
|
79
|
+
parameters:
|
80
|
+
gemfile:
|
81
|
+
- "gemfiles/activerecord_5_2.gemfile"
|
82
|
+
- "gemfiles/activerecord_6_0.gemfile"
|
83
|
+
- "gemfiles/activerecord_6_1.gemfile"
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/Appraisals
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
appraise 'activerecord_5_2' do
|
4
|
+
gem 'activerecord', '~> 5.2.0'
|
5
|
+
end
|
6
|
+
|
7
|
+
appraise 'activerecord_6_0' do
|
8
|
+
gem 'activerecord', '~> 6.0.0'
|
3
9
|
end
|
4
10
|
|
5
|
-
appraise '
|
6
|
-
gem 'activerecord', '
|
11
|
+
appraise 'activerecord_6_1' do
|
12
|
+
gem 'activerecord', '~> 6.1.0'
|
7
13
|
end
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Build Status](https://
|
1
|
+
[![Build Status](https://circleci.com/gh/salsify/postgres-vacuum-monitor.svg?style=svg)][circleci]
|
2
2
|
[![Maintainability](https://api.codeclimate.com/v1/badges/9ced178ca8fee231a935/maintainability)](https://codeclimate.com/github/salsify/postgres-vacuum-monitor/maintainability)
|
3
3
|
[![Coverage Status](https://coveralls.io/repos/github/salsify/postgres-vacuum-monitor/badge.svg?branch=master)](https://coveralls.io/github/salsify/postgres-vacuum-monitor?branch=master)
|
4
4
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'postgres/vacuum/monitor'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "postgres/vacuum/monitor"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Postgres
|
4
|
+
module Vacuum
|
5
|
+
class Compatibility
|
6
|
+
ACTIVE_RECORD_VERSION = ::Gem::Version.new(::ActiveRecord::VERSION::STRING).release
|
7
|
+
PRE_RAILS_6_1 = ACTIVE_RECORD_VERSION < ::Gem::Version.new('6.1.0')
|
8
|
+
|
9
|
+
def self.pre_rails_6_1?
|
10
|
+
PRE_RAILS_6_1
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Postgres
|
2
4
|
module Vacuum
|
3
5
|
module Jobs
|
4
6
|
class MonitorJob
|
5
7
|
|
6
|
-
AUTOVACUUM_LAGGING_EVENT = 'AutoVacuumLagging'
|
7
|
-
LONG_TRANSACTIONS = 'LongTransactions'
|
8
|
-
BLOCKED_QUERIES = 'BlockedQueries'
|
9
|
-
CONNECTION_STATE = 'ConnectionState'
|
10
|
-
CONNECTION_IDLE_TIME = 'ConnectionIdleTime'
|
8
|
+
AUTOVACUUM_LAGGING_EVENT = 'AutoVacuumLagging'
|
9
|
+
LONG_TRANSACTIONS = 'LongTransactions'
|
10
|
+
BLOCKED_QUERIES = 'BlockedQueries'
|
11
|
+
CONNECTION_STATE = 'ConnectionState'
|
12
|
+
CONNECTION_IDLE_TIME = 'ConnectionIdleTime'
|
11
13
|
|
12
14
|
def perform(*)
|
13
15
|
with_each_db_name_and_connection do |name, connection|
|
@@ -51,7 +53,12 @@ module Postgres
|
|
51
53
|
end
|
52
54
|
|
53
55
|
connection.execute(Postgres::Vacuum::Monitor::Query.connection_state).each do |row|
|
54
|
-
reporter_class.report_event(
|
56
|
+
reporter_class.report_event(
|
57
|
+
CONNECTION_STATE,
|
58
|
+
database_name: name,
|
59
|
+
state: row['state'],
|
60
|
+
connection_count: row['connection_count']
|
61
|
+
)
|
55
62
|
end
|
56
63
|
|
57
64
|
connection.execute(Postgres::Vacuum::Monitor::Query.connection_idle_time).each do |row|
|
@@ -72,7 +79,9 @@ module Postgres
|
|
72
79
|
return @reporter_class_name if @reporter_class_name
|
73
80
|
|
74
81
|
@reporter_class_name = Postgres::Vacuum::Monitor.configuration.monitor_reporter_class_name&.safe_constantize
|
75
|
-
|
82
|
+
if @reporter_class_name.nil?
|
83
|
+
raise ConfigurationError.new('Missing or invalid report class name. Check your configuration')
|
84
|
+
end
|
76
85
|
|
77
86
|
@reporter_class_name
|
78
87
|
end
|
@@ -80,7 +89,12 @@ module Postgres
|
|
80
89
|
def with_each_db_name_and_connection
|
81
90
|
databases = Set.new
|
82
91
|
ActiveRecord::Base.connection_handler.connection_pools.map do |connection_pool|
|
83
|
-
db_name =
|
92
|
+
db_name = if Postgres::Vacuum::Compatibility.pre_rails_6_1?
|
93
|
+
connection_pool.spec.config[:database]
|
94
|
+
else
|
95
|
+
connection_pool.db_config.configuration_hash[:database]
|
96
|
+
end
|
97
|
+
|
84
98
|
# activerecord allocates a connection pool per call to establish_connection
|
85
99
|
# multiple pools might interact with the same database so we use the
|
86
100
|
# database name to dedup
|
@@ -1,4 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_record'
|
4
|
+
require 'postgres/vacuum/compatibility'
|
2
5
|
require 'postgres/vacuum/configuration'
|
3
6
|
require 'postgres/vacuum/monitor/version'
|
4
7
|
require 'postgres/vacuum/monitor/query'
|
@@ -12,7 +15,7 @@ module Postgres
|
|
12
15
|
end
|
13
16
|
|
14
17
|
def self.configuration
|
15
|
-
@
|
18
|
+
@configuration ||= Configuration.new
|
16
19
|
end
|
17
20
|
|
18
21
|
def self.reset
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Postgres
|
2
4
|
module Vacuum
|
3
5
|
module Monitor
|
@@ -5,10 +7,10 @@ module Postgres
|
|
5
7
|
extend self
|
6
8
|
|
7
9
|
STATES = ["'idle in transaction'", "'active'"].freeze
|
8
|
-
THRESHOLD_SETTING = "'autovacuum_vacuum_threshold'"
|
9
|
-
SCALE_FACTOR_SETTING = "'autovacuum_vacuum_scale_factor'"
|
10
|
-
MAX_AGE_SETTING = "'autovacuum_freeze_max_age'"
|
11
|
-
PG_CATALOG = "'pg_catalog'"
|
10
|
+
THRESHOLD_SETTING = "'autovacuum_vacuum_threshold'"
|
11
|
+
SCALE_FACTOR_SETTING = "'autovacuum_vacuum_scale_factor'"
|
12
|
+
MAX_AGE_SETTING = "'autovacuum_freeze_max_age'"
|
13
|
+
PG_CATALOG = "'pg_catalog'"
|
12
14
|
|
13
15
|
def long_running_transactions
|
14
16
|
<<-SQL
|
@@ -81,7 +83,7 @@ module Postgres
|
|
81
83
|
blocking_activity.application_name AS blocking_application
|
82
84
|
FROM pg_catalog.pg_locks blocked_locks
|
83
85
|
JOIN pg_catalog.pg_stat_activity blocked_activity ON blocked_activity.pid = blocked_locks.pid
|
84
|
-
JOIN pg_catalog.pg_locks blocking_locks
|
86
|
+
JOIN pg_catalog.pg_locks blocking_locks
|
85
87
|
ON blocking_locks.locktype = blocked_locks.locktype
|
86
88
|
AND blocking_locks.DATABASE IS NOT DISTINCT FROM blocked_locks.DATABASE
|
87
89
|
AND blocking_locks.relation IS NOT DISTINCT FROM blocked_locks.relation
|
@@ -100,10 +102,10 @@ module Postgres
|
|
100
102
|
|
101
103
|
def connection_state
|
102
104
|
<<-SQL
|
103
|
-
SELECT
|
104
|
-
state, count(*) as connection_count
|
105
|
-
FROM pg_stat_activity
|
106
|
-
GROUP BY state
|
105
|
+
SELECT
|
106
|
+
state, count(*) as connection_count
|
107
|
+
FROM pg_stat_activity
|
108
|
+
GROUP BY state
|
107
109
|
ORDER BY connection_count DESC;
|
108
110
|
SQL
|
109
111
|
end
|
@@ -1,5 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
lib = File.expand_path('
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'postgres/vacuum/monitor/version'
|
5
6
|
|
@@ -10,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
10
11
|
spec.email = ['fgarces@salsify.com']
|
11
12
|
|
12
13
|
spec.summary = 'Simple stats collector for postgres auto vacuumer.'
|
13
|
-
spec.description = 'Queries
|
14
|
+
spec.description = 'Queries ActiveRecord DBs for info regarding auto vacuum processes and long running queries.'
|
14
15
|
spec.homepage = 'https://github.com/salsify/postgres-vacuum-monitor'
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
@@ -26,10 +27,11 @@ Gem::Specification.new do |spec|
|
|
26
27
|
spec.add_development_dependency 'bundler'
|
27
28
|
spec.add_development_dependency 'coveralls_reborn', '>= 0.18.0'
|
28
29
|
spec.add_development_dependency 'database_cleaner'
|
29
|
-
spec.add_development_dependency 'rake'
|
30
|
+
spec.add_development_dependency 'rake'
|
30
31
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
32
|
+
spec.add_development_dependency 'rspec_junit_formatter'
|
31
33
|
spec.add_development_dependency 'salsify_rubocop'
|
32
34
|
|
33
|
-
spec.add_dependency 'activerecord', '
|
35
|
+
spec.add_dependency 'activerecord', '< 6.2.0'
|
34
36
|
spec.add_dependency 'pg', '>= 0.18', '< 2.0'
|
35
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postgres-vacuum-monitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernando Garces
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.2'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rspec_junit_formatter
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,25 +109,33 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: salsify_rubocop
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: activerecord
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
118
129
|
- - "<"
|
119
130
|
- !ruby/object:Gem::Version
|
120
|
-
version:
|
131
|
+
version: 6.2.0
|
121
132
|
type: :runtime
|
122
133
|
prerelease: false
|
123
134
|
version_requirements: !ruby/object:Gem::Requirement
|
124
135
|
requirements:
|
125
|
-
- - ">="
|
126
|
-
- !ruby/object:Gem::Version
|
127
|
-
version: '5'
|
128
136
|
- - "<"
|
129
137
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
138
|
+
version: 6.2.0
|
131
139
|
- !ruby/object:Gem::Dependency
|
132
140
|
name: pg
|
133
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -148,18 +156,18 @@ dependencies:
|
|
148
156
|
- - "<"
|
149
157
|
- !ruby/object:Gem::Version
|
150
158
|
version: '2.0'
|
151
|
-
description: Queries
|
152
|
-
|
159
|
+
description: Queries ActiveRecord DBs for info regarding auto vacuum processes and
|
160
|
+
long running queries.
|
153
161
|
email:
|
154
162
|
- fgarces@salsify.com
|
155
163
|
executables: []
|
156
164
|
extensions: []
|
157
165
|
extra_rdoc_files: []
|
158
166
|
files:
|
167
|
+
- ".circleci/config.yml"
|
159
168
|
- ".gitignore"
|
160
169
|
- ".rspec"
|
161
170
|
- ".rubocop.yml"
|
162
|
-
- ".travis.yml"
|
163
171
|
- Appraisals
|
164
172
|
- CHANGELOG.md
|
165
173
|
- CODE_OF_CONDUCT.md
|
@@ -169,8 +177,10 @@ files:
|
|
169
177
|
- Rakefile
|
170
178
|
- bin/console
|
171
179
|
- bin/setup
|
172
|
-
- gemfiles/
|
173
|
-
- gemfiles/
|
180
|
+
- gemfiles/activerecord_5_2.gemfile
|
181
|
+
- gemfiles/activerecord_6_0.gemfile
|
182
|
+
- gemfiles/activerecord_6_1.gemfile
|
183
|
+
- lib/postgres/vacuum/compatibility.rb
|
174
184
|
- lib/postgres/vacuum/configuration.rb
|
175
185
|
- lib/postgres/vacuum/jobs/monitor_job.rb
|
176
186
|
- lib/postgres/vacuum/monitor.rb
|
data/.travis.yml
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.5.8
|
4
|
-
- 2.6.6
|
5
|
-
- 2.7.1
|
6
|
-
gemfile:
|
7
|
-
- gemfiles/activerecord_5.gemfile
|
8
|
-
- gemfiles/activerecord_6.gemfile
|
9
|
-
services:
|
10
|
-
- postgresql
|
11
|
-
before_script:
|
12
|
-
- psql -c 'create database postgres_vacuum_monitor_test;' -U postgres
|
13
|
-
addons:
|
14
|
-
postgresql: '9.6'
|