sensu-plugins-postgres 4.0.2 → 4.1.0
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 +4 -4
- data/CHANGELOG.md +6 -1
- data/bin/metric-postgres-vaccum.rb +124 -0
- data/lib/sensu-plugins-postgres/version.rb +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d435ce57d91a2e6a71c1971cd1602f19b82004f70f82aa498770c110c8bf266
|
4
|
+
data.tar.gz: 64ddf283f041bd5b70eac42d7433e8a0dad64226858723e4e8c56a5f983f819f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d91e6b7648feab7e75431930bc7a739448276d233df4c2afd8cb9084ebbbb488878ab5a5936422355fcb9a34dcec6699db279afeeee52798b66390d32761bcb8
|
7
|
+
data.tar.gz: 824cc884e247f23a9ffdb0aa60e4e3a90bda1fd2e4d10badcbaf8934d6e08fa77d00a53599c8331ea209381696923779d8d7bb9f433c5aeee78ec6418df4150b
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
|
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
7
|
|
8
|
+
## [4.1.0] - 2020-06-04
|
9
|
+
### Added
|
10
|
+
- new `metric-postgres-vaccum.rb` metric gathering script for postgres vacuum process (@phumpal)
|
11
|
+
|
8
12
|
## [4.0.2] - 2020-06-02
|
9
13
|
- Fixed `# frozen_string_literal: true` does not play nicely with mixlib-cli.
|
10
14
|
|
@@ -213,7 +217,8 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
|
|
213
217
|
### Added
|
214
218
|
- initial release
|
215
219
|
|
216
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.0
|
220
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.1.0...HEAD
|
221
|
+
[4.1.0]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.0.2...4.1.0
|
217
222
|
[4.0.2]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.0.1...4.0.2
|
218
223
|
[4.0.1]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.0.0...4.0.1
|
219
224
|
[4.0.0]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/3.0.0...4.0.0
|
@@ -0,0 +1,124 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# DEPENDENCIES:
|
5
|
+
# gem: sensu-plugin
|
6
|
+
# gem: pg
|
7
|
+
#
|
8
|
+
# USAGE:
|
9
|
+
# ./metric-postgres-vaccum.rb -u db_user -p db_pass -h db_host -d db
|
10
|
+
#
|
11
|
+
# NOTES:
|
12
|
+
# Requires PSQL `track_counts` `track_io_timing` for some metrics enabled
|
13
|
+
#
|
14
|
+
# LICENSE:
|
15
|
+
# Copyright (c) 2020 Airbrake Technologies, Inc <support@airbrake.io>
|
16
|
+
# Author Patrick Humpal <patrick@netvilla.net>
|
17
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
18
|
+
# for details.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'sensu-plugins-postgres/pgpass'
|
22
|
+
require 'sensu-plugin/metric/cli'
|
23
|
+
require 'pg'
|
24
|
+
require 'socket'
|
25
|
+
|
26
|
+
class PostgresVacuumDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
27
|
+
option :pgpass,
|
28
|
+
description: 'Pgpass file',
|
29
|
+
short: '-f FILE',
|
30
|
+
long: '--pgpass',
|
31
|
+
default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass"
|
32
|
+
|
33
|
+
option :user,
|
34
|
+
description: 'Postgres User',
|
35
|
+
short: '-u USER',
|
36
|
+
long: '--user USER'
|
37
|
+
|
38
|
+
option :password,
|
39
|
+
description: 'Postgres Password',
|
40
|
+
short: '-p PASS',
|
41
|
+
long: '--password PASS'
|
42
|
+
|
43
|
+
option :hostname,
|
44
|
+
description: 'Hostname to login to',
|
45
|
+
short: '-h HOST',
|
46
|
+
long: '--hostname HOST'
|
47
|
+
|
48
|
+
option :port,
|
49
|
+
description: 'Database port',
|
50
|
+
short: '-P PORT',
|
51
|
+
long: '--port PORT'
|
52
|
+
|
53
|
+
option :database,
|
54
|
+
description: 'Database to connect on',
|
55
|
+
short: '-d DB',
|
56
|
+
long: '--db DB',
|
57
|
+
default: 'postgres'
|
58
|
+
|
59
|
+
option :all_databases,
|
60
|
+
description: 'Get stats for all available databases',
|
61
|
+
short: '-a',
|
62
|
+
long: '--all-databases',
|
63
|
+
boolean: true,
|
64
|
+
default: false
|
65
|
+
|
66
|
+
option :scheme,
|
67
|
+
description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
|
68
|
+
long: '--scheme SCHEME',
|
69
|
+
default: "#{Socket.gethostname}.postgresql"
|
70
|
+
|
71
|
+
option :timeout,
|
72
|
+
description: 'Connection timeout (seconds)',
|
73
|
+
short: '-T TIMEOUT',
|
74
|
+
long: '--timeout TIMEOUT',
|
75
|
+
default: nil
|
76
|
+
|
77
|
+
include Pgpass
|
78
|
+
|
79
|
+
def phase_mapping(vacuum_phase)
|
80
|
+
['initializing',
|
81
|
+
'scanning heap',
|
82
|
+
'vacuuming indexes',
|
83
|
+
'vacuuming heap',
|
84
|
+
'cleaning up indexes',
|
85
|
+
'truncating heap',
|
86
|
+
'performing final cleanup'].find_index(vacuum_phase)
|
87
|
+
end
|
88
|
+
|
89
|
+
def run
|
90
|
+
timestamp = Time.now.to_i
|
91
|
+
pgpass
|
92
|
+
con = PG.connect(host: config[:hostname],
|
93
|
+
dbname: config[:database],
|
94
|
+
user: config[:user],
|
95
|
+
password: config[:password],
|
96
|
+
port: config[:port],
|
97
|
+
connect_timeout: config[:timeout])
|
98
|
+
|
99
|
+
query = 'SELECT * FROM pg_stat_progress_vacuum'
|
100
|
+
params = []
|
101
|
+
unless config[:all_databases]
|
102
|
+
query += ' WHERE datname = $1'
|
103
|
+
params.push config[:database]
|
104
|
+
end
|
105
|
+
|
106
|
+
con.exec_params(query, params) do |result|
|
107
|
+
result.each do |row|
|
108
|
+
database = row['datname']
|
109
|
+
|
110
|
+
row.each do |key, value|
|
111
|
+
next if %w[datid datname].include?(key)
|
112
|
+
|
113
|
+
if key == 'phase'
|
114
|
+
output "#{config[:scheme]}.vacuum.#{database}.phase", phase_mapping(value).to_s, timestamp
|
115
|
+
else
|
116
|
+
output "#{config[:scheme]}.vacuum.#{database}.#{key}", value.to_s, timestamp
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
ok
|
123
|
+
end
|
124
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-postgres
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-plugin
|
@@ -270,6 +270,7 @@ executables:
|
|
270
270
|
- metric-postgres-locks.rb
|
271
271
|
- metric-postgres-statsbgwriter.rb
|
272
272
|
- check-postgres-replication.rb
|
273
|
+
- metric-postgres-vaccum.rb
|
273
274
|
extensions: []
|
274
275
|
extra_rdoc_files: []
|
275
276
|
files:
|
@@ -288,6 +289,7 @@ files:
|
|
288
289
|
- bin/metric-postgres-statsdb.rb
|
289
290
|
- bin/metric-postgres-statsio.rb
|
290
291
|
- bin/metric-postgres-statstable.rb
|
292
|
+
- bin/metric-postgres-vaccum.rb
|
291
293
|
- bin/metrics-postgres-query.rb
|
292
294
|
- lib/sensu-plugins-postgres.rb
|
293
295
|
- lib/sensu-plugins-postgres/pgpass.rb
|