postgres-vacuum-monitor 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db00fc91bc1a6bab49018555f0663b9ec892021cb2c65984ff7c32676bece583
4
- data.tar.gz: 924748bb6d70683a656e3c0a51eed83508b9eba3e54a39291445b5c785f8b03f
3
+ metadata.gz: d73b82c8aa8fbc2cf16b5685a23b67069b5ff8b41ff37d8b7db91aa69fac3b28
4
+ data.tar.gz: 2ea1469236728dc0c60637739c59b2de265c86bc7116e33185cba0972d1fe06f
5
5
  SHA512:
6
- metadata.gz: 13af0f7be1384e6582c4c2c8b037af0a9aa1d02f10ccb22a6717f1dd5a6060aa6e207cb16b198355a2c5b3f9ccb91b20d6f55414f6644107941215985b9dfab5
7
- data.tar.gz: cc9d708511f7ca663f4578019b19fe4130ed5f497e1def24c7da937bdf364803037521b1ba06b0390c5fb723ebaf131868ecaf0d5aa2912e3dd35a244a71c574
6
+ metadata.gz: e8d61553c2c18274abbae680870b814a9f87093ae06e8fd55cd9201b86264abd44bd82f05ddb320ce64b2edae7d30a14a879b56bd4f856825bbb6ac9a497398a
7
+ data.tar.gz: 77d63951bded8bf220ae133a518ebf1d862e84a83253eaa37462f6998b599896de255514391ef0e67ae4baf5c04f7b9af6104d658383a054b11e54bd5bce3301
data/CHANGELOG.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # postgres-vacuum-monitor
2
+ ## v.0.3.2
3
+ - Monitor non-ActiveRecord::Base database connections
4
+
2
5
  ## v.0.3.1
3
6
  - Relax pg requirements
4
7
 
data/README.md CHANGED
@@ -47,6 +47,7 @@ end
47
47
  For long running queries, the event name is `LongQueries` and the attributes are:
48
48
  ```ruby
49
49
  {
50
+ database_name: # The name of the database.
50
51
  start_time: # When the query started .
51
52
  running_time: # How long has it been running in seconds.
52
53
  application_name: # What's the application name that is running the query.
@@ -58,6 +59,7 @@ For auto vacuum the attributes are the following:
58
59
 
59
60
  ```ruby
60
61
  {
62
+ database_name: # The name of the database.
61
63
  table: # Table name.
62
64
  table_size: # How big is the table.
63
65
  dead_tuples: # How many dead tuples are in the table.
@@ -7,24 +7,28 @@ module Postgres
7
7
  LONG_QUERIES = 'LongQueries'.freeze
8
8
 
9
9
  def perform(*)
10
- ActiveRecord::Base.connection.execute(Postgres::Vacuum::Monitor::Query.long_running_queries).each do |row|
11
- reporter_class.report_event(
12
- LONG_QUERIES,
13
- start_time: row['xact_start'],
14
- running_time: row['seconds'],
15
- application_name: row['application_name'],
16
- query: row['query']
17
- )
18
- end
19
-
20
- ActiveRecord::Base.connection.execute(Postgres::Vacuum::Monitor::Query.tables_eligible_vacuuming).each do |row|
21
- reporter_class.report_event(
22
- AUTOVACUUM_QUERY_EVENT,
23
- table: row['relation'],
24
- table_size: row['table_size'],
25
- dead_tuples: row['dead_tuples'].to_i,
26
- tuples_over_limit: row['dead_tuples'].to_i - row['autovacuum_vacuum_tuples'].to_i
27
- )
10
+ with_each_db_name_and_connection do |name, connection|
11
+ connection.execute(Postgres::Vacuum::Monitor::Query.long_running_queries).each do |row|
12
+ reporter_class.report_event(
13
+ LONG_QUERIES,
14
+ database_name: name,
15
+ start_time: row['xact_start'],
16
+ running_time: row['seconds'],
17
+ application_name: row['application_name'],
18
+ query: row['query']
19
+ )
20
+ end
21
+
22
+ connection.execute(Postgres::Vacuum::Monitor::Query.tables_eligible_vacuuming).each do |row|
23
+ reporter_class.report_event(
24
+ AUTOVACUUM_QUERY_EVENT,
25
+ database_name: name,
26
+ table: row['relation'],
27
+ table_size: row['table_size'],
28
+ dead_tuples: row['dead_tuples'].to_i,
29
+ tuples_over_limit: row['dead_tuples'].to_i - row['autovacuum_vacuum_tuples'].to_i
30
+ )
31
+ end
28
32
  end
29
33
 
30
34
  true
@@ -39,6 +43,17 @@ module Postgres
39
43
  @reporter_class_name
40
44
  end
41
45
 
46
+ def with_each_db_name_and_connection
47
+ databases = Set.new
48
+ ActiveRecord::Base.connection_handler.connection_pools.map do |connection_pool|
49
+ db_name = connection_pool.spec.config[:database]
50
+ # activerecord allocates a connection pool per call to establish_connection
51
+ # multiple pools might interact with the same database so we use the
52
+ # database name to dedup
53
+ connection_pool.with_connection { |conn| yield(db_name, conn) } if databases.add?(db_name)
54
+ end
55
+ end
56
+
42
57
  ConfigurationError = Class.new(StandardError)
43
58
  end
44
59
  end
@@ -1,7 +1,7 @@
1
1
  module Postgres
2
2
  module Vacuum
3
3
  module Monitor
4
- VERSION = '0.3.1'.freeze
4
+ VERSION = '0.3.2'.freeze
5
5
  end
6
6
  end
7
7
  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.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Garces
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-04 00:00:00.000000000 Z
11
+ date: 2019-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  requirements: []
196
- rubygems_version: 3.0.2
196
+ rubygems_version: 3.0.4
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: Simple stats collector for postgres auto vacuumer.