sensu-plugins-postgres 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 131a846f47b8f69d676bd2f420e493be5188250e
4
+ data.tar.gz: f14dce699db43e1096f59169a25fe29b41ad3cc1
5
+ SHA512:
6
+ metadata.gz: b3f4f0786e3aa153ccf34703c6885d0532242d34715628f98cad0dfbb9e36af81ddc8abe092605d544488c29bdb845eeb905f18cb18572b7ef4f65a1ab7fb70a
7
+ data.tar.gz: 99d8733c87a307bd9d4b27b6406621bdde6925e0eb281c84f4a4bc874bfcac5a3d3bd8853f4e179364464b5fc815e15073dd8666e80badb8f8bb469b7bebba1f
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ #Change Log
2
+ This project adheres to [Semantic Versioning](http://semver.org/).
3
+
4
+ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
5
+
6
+ ## Unreleased][unreleased]
7
+
8
+ ## 0.0.1 - 2015-04-30
9
+
10
+ ### Added
11
+ - initial release
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Sensu-Plugins
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ ## Sensu-Plugins-postgres
2
+
3
+ [![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-postgres.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-postgres)
4
+ [![Gem Version](https://badge.fury.io/rb/sensu-plugins-postgres.svg)](http://badge.fury.io/rb/sensu-plugins-postgres)
5
+ [![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-postgres/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-postgres)
6
+ [![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-postgres/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-postgres)
7
+ [![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-postgres.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-postgres)
8
+ [![Codeship Status for sensu-plugins/sensu-plugins-postgres](https://codeship.com/projects/985aceb0-e89b-0132-adeb-62885e5c211b/status?branch=master)](https://codeship.com/projects/82843)
9
+
10
+ ## Functionality
11
+
12
+ ## Files
13
+ * bin/check-postgres-alive.rb
14
+ * bin/metric-postgres-dbsize.rb
15
+ * bin/metric-postgres-statsbgwriter.rb
16
+ * bin/metric-postgres-statstable.rb
17
+ * bin/check-postgres-replication.rb
18
+ * bin/metric-postgres-graphite.rb
19
+ * bin/metric-postgres-statsdb.rb
20
+ * bin/metric-postgres-connections.rb
21
+ * bin/metric-postgres-locks.rb
22
+ * bin/metric-postgres-statsio.rb
23
+
24
+ ## Usage
25
+
26
+ ## Installation
27
+
28
+ [Installation and Setup](https://github.com/sensu-plugins/documentation/blob/master/user_docs/installation_instructions.md)
29
+
30
+ ## Notes
31
+
32
+ [1]:[https://travis-ci.org/sensu-plugins/sensu-plugins-postgres]
33
+ [2]:[http://badge.fury.io/rb/sensu-plugins-postgres]
34
+ [3]:[https://codeclimate.com/github/sensu-plugins/sensu-plugins-postgres]
35
+ [4]:[https://codeclimate.com/github/sensu-plugins/sensu-plugins-postgres]
36
+ [5]:[https://gemnasium.com/sensu-plugins/sensu-plugins-postgres]
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Postgres Alive Plugin
4
+ #
5
+ # This plugin attempts to login to postgres with provided credentials.
6
+ #
7
+ # Copyright 2012 Lewis Preson & Tom Bassindale
8
+ #
9
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
10
+ # for details.
11
+
12
+ require 'sensu-plugin/check/cli'
13
+ require 'pg'
14
+
15
+ class CheckPostgres < Sensu::Plugin::Check::CLI
16
+ option :user,
17
+ description: 'Postgres User',
18
+ short: '-u USER',
19
+ long: '--user USER'
20
+
21
+ option :password,
22
+ description: 'Postgres Password',
23
+ short: '-p PASS',
24
+ long: '--password PASS'
25
+
26
+ option :hostname,
27
+ description: 'Hostname to login to',
28
+ short: '-h HOST',
29
+ long: '--hostname HOST'
30
+
31
+ option :database,
32
+ description: 'Database schema to connect to',
33
+ short: '-d DATABASE',
34
+ long: '--database DATABASE',
35
+ default: 'test'
36
+
37
+ option :port,
38
+ description: 'Database port',
39
+ short: '-P PORT',
40
+ long: '--port PORT',
41
+ default: 5432
42
+
43
+ def run
44
+ con = PG::Connection.new(config[:hostname], config[:port], nil, nil, config[:database], config[:user], config[:password])
45
+ res = con.exec('select version();')
46
+ info = res.first
47
+
48
+ ok "Server version: #{info}"
49
+ rescue PG::Error => e
50
+ critical "Error message: #{e.error.split("\n").first}"
51
+ ensure
52
+ con.close if con
53
+ end
54
+ end
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sensu-plugin/check/cli'
4
+ require 'pg'
5
+
6
+ class CheckPostgresReplicationStatus < Sensu::Plugin::Check::CLI
7
+ option(:master_host,
8
+ short: '-m',
9
+ long: '--master-host=HOST',
10
+ description: 'PostgreSQL master HOST')
11
+
12
+ option(:slave_host,
13
+ short: '-s',
14
+ long: '--slave-host=HOST',
15
+ description: 'PostgreSQL slave HOST',
16
+ default: 'localhost')
17
+
18
+ option(:database,
19
+ short: '-d',
20
+ long: '--database=NAME',
21
+ description: 'Database NAME')
22
+
23
+ option(:user,
24
+ short: '-u',
25
+ long: '--user=USER',
26
+ description: 'Database USER')
27
+
28
+ option(:password,
29
+ short: '-p',
30
+ long: '--password=PASSWORD',
31
+ description: 'Database PASSWORD')
32
+
33
+ option(:ssl,
34
+ short: '-s',
35
+ long: '--ssl',
36
+ boolean: true,
37
+ description: 'Require SSL')
38
+
39
+ option(:warn,
40
+ short: '-w',
41
+ long: '--warning=VALUE',
42
+ description: 'Warning threshold for replication lag (in MB)',
43
+ default: 900,
44
+ # #YELLOW
45
+ proc: lambda { |s| s.to_i }) # rubocop:disable Lambda
46
+
47
+ option(:crit,
48
+ short: '-c',
49
+ long: '--critical=VALUE',
50
+ description: 'Critical threshold for replication lag (in MB)',
51
+ default: 1800,
52
+ # #YELLOW
53
+ proc: lambda { |s| s.to_i }) # rubocop:disable Lambda
54
+
55
+ def compute_lag(master, slave, m_segbytes)
56
+ m_segment, m_offset = master.split('/')
57
+ s_segment, s_offset = slave.split('/')
58
+ ((m_segment.hex - s_segment.hex) * m_segbytes) + (m_offset.hex - s_offset.hex)
59
+ end
60
+
61
+ def run
62
+ ssl_mode = config[:ssl] ? 'require' : 'prefer'
63
+
64
+ # Establishing connection to the master
65
+ conn_master = PG.connect(host: config[:master_host],
66
+ dbname: config[:database],
67
+ user: config[:user],
68
+ password: config[:password],
69
+ sslmode: ssl_mode)
70
+
71
+ master = conn_master.exec('SELECT pg_current_xlog_location()').getvalue(0, 0)
72
+ m_segbytes = conn_master.exec('SHOW wal_segment_size').getvalue(0, 0).sub(/\D+/, '').to_i << 20
73
+ conn_master.close
74
+
75
+ # Establishing connection to the slave
76
+ conn_slave = PG.connect(host: config[:slave_host],
77
+ dbname: config[:database],
78
+ user: config[:user],
79
+ password: config[:password],
80
+ sslmode: ssl_mode)
81
+
82
+ slave = conn_slave.exec('SELECT pg_last_xlog_receive_location()').getvalue(0, 0)
83
+ conn_slave.close
84
+
85
+ # Computing lag
86
+ lag = compute_lag(master, slave, m_segbytes)
87
+ lag_in_mb = (lag.to_f / 1024 / 1024).abs
88
+
89
+ message = "replication delayed by #{lag_in_mb}MB :: master:#{master} slave:#{slave} m_segbytes:#{m_segbytes}"
90
+
91
+ case
92
+ when lag_in_mb >= config[:crit]
93
+ critical message
94
+ when lag_in_mb >= config[:warn]
95
+ warning message
96
+ else
97
+ ok message
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Postgres Connection Metrics
4
+ # ===
5
+ #
6
+ # Dependencies
7
+ # -----------
8
+ # - Ruby gem `pg`
9
+ #
10
+ #
11
+ # Copyright 2012 Kwarter, Inc <platforms@kwarter.com>
12
+ # Author Gilles Devaux <gilles.devaux@gmail.com>
13
+ #
14
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
15
+ # for details.
16
+
17
+ require 'sensu-plugin/metric/cli'
18
+ require 'pg'
19
+ require 'socket'
20
+
21
+ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
22
+ option :user,
23
+ description: 'Postgres User',
24
+ short: '-u USER',
25
+ long: '--user USER'
26
+
27
+ option :password,
28
+ description: 'Postgres Password',
29
+ short: '-p PASS',
30
+ long: '--password PASS'
31
+
32
+ option :hostname,
33
+ description: 'Hostname to login to',
34
+ short: '-h HOST',
35
+ long: '--hostname HOST',
36
+ default: 'localhost'
37
+
38
+ option :port,
39
+ description: 'Database port',
40
+ short: '-P PORT',
41
+ long: '--port PORT',
42
+ default: 5432
43
+
44
+ option :db,
45
+ description: 'Database name',
46
+ short: '-d DB',
47
+ long: '--db DB',
48
+ default: 'postgres'
49
+
50
+ option :scheme,
51
+ description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
52
+ long: '--scheme SCHEME',
53
+ default: "#{Socket.gethostname}.postgresql"
54
+
55
+ def run
56
+ timestamp = Time.now.to_i
57
+
58
+ con = PG::Connection.new(config[:hostname], config[:port], nil, nil, 'postgres', config[:user], config[:password])
59
+ request = [
60
+ 'select count(*), waiting from pg_stat_activity',
61
+ "where datname = '#{config[:db]}' group by waiting"
62
+ ]
63
+
64
+ metrics = {
65
+ active: 0,
66
+ waiting: 0
67
+ }
68
+ con.exec(request.join(' ')) do |result|
69
+ result.each do |row|
70
+ if row['waiting']
71
+ metrics[:waiting] = row['count']
72
+ else
73
+ metrics[:active] = row['count']
74
+ end
75
+ end
76
+ end
77
+
78
+ metrics.each do |metric, value|
79
+ output "#{config[:scheme]}.connections.#{config[:db]}.#{metric}", value, timestamp
80
+ end
81
+
82
+ ok
83
+ end
84
+ end
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Postgres DBSize Metrics
4
+ # ===
5
+ #
6
+ # Dependencies
7
+ # -----------
8
+ # - Ruby gem `pg`
9
+ #
10
+ #
11
+ # Copyright 2012 Kwarter, Inc <platforms@kwarter.com>
12
+ # Author Gilles Devaux <gilles.devaux@gmail.com>
13
+ #
14
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
15
+ # for details.
16
+
17
+ require 'sensu-plugin/metric/cli'
18
+ require 'pg'
19
+ require 'socket'
20
+
21
+ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
22
+ option :user,
23
+ description: 'Postgres User',
24
+ short: '-u USER',
25
+ long: '--user USER'
26
+
27
+ option :password,
28
+ description: 'Postgres Password',
29
+ short: '-p PASS',
30
+ long: '--password PASS'
31
+
32
+ option :hostname,
33
+ description: 'Hostname to login to',
34
+ short: '-h HOST',
35
+ long: '--hostname HOST',
36
+ default: 'localhost'
37
+
38
+ option :port,
39
+ description: 'Database port',
40
+ short: '-P PORT',
41
+ long: '--port PORT',
42
+ default: 5432
43
+
44
+ option :db,
45
+ description: 'Database name',
46
+ short: '-d DB',
47
+ long: '--db DB',
48
+ default: 'postgres'
49
+
50
+ option :scheme,
51
+ description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
52
+ long: '--scheme SCHEME',
53
+ default: "#{Socket.gethostname}.postgresql"
54
+
55
+ def run
56
+ timestamp = Time.now.to_i
57
+
58
+ con = PG::Connection.new(config[:hostname], config[:port], nil, nil, 'postgres', config[:user], config[:password])
59
+ request = [
60
+ "select pg_database_size('#{config[:db]}')"
61
+ ]
62
+
63
+ con.exec(request.join(' ')) do |result|
64
+ result.each do |row|
65
+ output "#{config[:scheme]}.size.#{config[:db]}", row['pg_database_size'], timestamp
66
+ end
67
+ end
68
+
69
+ ok
70
+ end
71
+ end
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pg'
4
+ require 'sensu-plugin/metric/cli'
5
+ require 'socket'
6
+
7
+ class CheckpostgresReplicationStatus < Sensu::Plugin::Metric::CLI::Graphite
8
+ option :master_host,
9
+ short: '-m',
10
+ long: '--master=HOST',
11
+ description: 'PostgreSQL master HOST'
12
+
13
+ option :slave_host,
14
+ short: '-s',
15
+ long: '--slave=HOST',
16
+ description: 'PostgreSQL slave HOST',
17
+ default: 'localhost'
18
+
19
+ option :database,
20
+ short: '-d',
21
+ long: '--database=NAME',
22
+ description: 'Database NAME',
23
+ default: 'postgres'
24
+
25
+ option :user,
26
+ short: '-u',
27
+ long: '--username=VALUE',
28
+ description: 'Database username'
29
+
30
+ option :pass,
31
+ short: '-p',
32
+ long: '--password=VALUE',
33
+ description: 'Database password'
34
+
35
+ option :scheme,
36
+ description: 'Metric naming scheme, text to prepend to metric',
37
+ short: '-g SCHEME',
38
+ long: '--scheme SCHEME',
39
+ default: "#{Socket.gethostname}.postgres.replication_lag"
40
+
41
+ def run
42
+ @dbmaster = config[:master_host]
43
+ @dbslave = config[:slave_host]
44
+ @dbport = 5432
45
+ @dbname = config[:database]
46
+ @dbusername = config[:user]
47
+ @password = config[:pass]
48
+
49
+ # Establishing connections to the master
50
+ conn_master = PGconn.connect(@dbmaster, @dbport, '', '', @dbname, @dbusername, @password)
51
+ res1 = conn_master.exec('SELECT pg_current_xlog_location()').getvalue(0, 0)
52
+ m_segbytes = conn_master.exec('SHOW wal_segment_size').getvalue(0, 0).sub(/\D+/, '').to_i << 20
53
+ conn_master.close
54
+
55
+ def lag_compute(res1, res, m_segbytes)
56
+ m_segment, m_offset = res1.split(/\//)
57
+ s_segment, s_offset = res.split(/\//)
58
+ ((m_segment.hex - s_segment.hex) * m_segbytes) + (m_offset.hex - s_offset.hex)
59
+ end
60
+
61
+ # Establishing connections to the slave
62
+ conn_slave = PGconn.connect(@dbslave, @dbport, '', '', @dbname, @dbusername, @password)
63
+ res = conn_slave.exec('SELECT pg_last_xlog_receive_location()').getvalue(0, 0)
64
+ conn_slave.close
65
+
66
+ # Compute lag
67
+ lag = lag_compute(res1, res, m_segbytes)
68
+ output "#{config[:scheme]}", lag
69
+
70
+ ok
71
+ end
72
+ end
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Postgres Locks Metrics
4
+ # ===
5
+ #
6
+ # Dependencies
7
+ # -----------
8
+ # - Ruby gem `pg`
9
+ #
10
+ #
11
+ # Copyright 2012 Kwarter, Inc <platforms@kwarter.com>
12
+ # Author Gilles Devaux <gilles.devaux@gmail.com>
13
+ #
14
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
15
+ # for details.
16
+
17
+ require 'sensu-plugin/metric/cli'
18
+ require 'pg'
19
+ require 'socket'
20
+
21
+ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
22
+ option :user,
23
+ description: 'Postgres User',
24
+ short: '-u USER',
25
+ long: '--user USER'
26
+
27
+ option :password,
28
+ description: 'Postgres Password',
29
+ short: '-p PASS',
30
+ long: '--password PASS'
31
+
32
+ option :hostname,
33
+ description: 'Hostname to login to',
34
+ short: '-h HOST',
35
+ long: '--hostname HOST',
36
+ default: 'localhost'
37
+
38
+ option :port,
39
+ description: 'Database port',
40
+ short: '-P PORT',
41
+ long: '--port PORT',
42
+ default: 5432
43
+
44
+ option :db,
45
+ description: 'Database name',
46
+ short: '-d DB',
47
+ long: '--db DB',
48
+ default: 'postgres'
49
+
50
+ option :scheme,
51
+ description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
52
+ long: '--scheme SCHEME',
53
+ default: "#{Socket.gethostname}.postgresql"
54
+
55
+ def run
56
+ timestamp = Time.now.to_i
57
+
58
+ locks_per_type = Hash.new(0)
59
+
60
+ con = PG::Connection.new(config[:hostname], config[:port], nil, nil, 'postgres', config[:user], config[:password])
61
+ request = [
62
+ 'SELECT mode, count(mode) FROM pg_locks',
63
+ "where database = (select oid from pg_database where datname = '#{config[:db]}')",
64
+ 'group by mode'
65
+ ]
66
+
67
+ con.exec(request.join(' ')) do |result|
68
+ result.each do |row|
69
+ lock_name = row['mode'].downcase.to_sym
70
+ locks_per_type[lock_name] += 1
71
+ end
72
+ end
73
+
74
+ locks_per_type.each do |lock_type, count|
75
+ output "#{config[:scheme]}.locks.#{config[:db]}.#{lock_type}", count, timestamp
76
+ end
77
+
78
+ ok
79
+ end
80
+ end
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Postgres Stat BGWriter Metrics
4
+ # ===
5
+ #
6
+ # Dependencies
7
+ # -----------
8
+ # - Ruby gem `pg`
9
+ #
10
+ #
11
+ # Copyright 2012 Kwarter, Inc <platforms@kwarter.com>
12
+ # Author Gilles Devaux <gilles.devaux@gmail.com>
13
+ #
14
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
15
+ # for details.
16
+
17
+ require 'sensu-plugin/metric/cli'
18
+ require 'pg'
19
+ require 'socket'
20
+
21
+ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
22
+ option :user,
23
+ description: 'Postgres User',
24
+ short: '-u USER',
25
+ long: '--user USER'
26
+
27
+ option :password,
28
+ description: 'Postgres Password',
29
+ short: '-p PASS',
30
+ long: '--password PASS'
31
+
32
+ option :hostname,
33
+ description: 'Hostname to login to',
34
+ short: '-h HOST',
35
+ long: '--hostname HOST',
36
+ default: 'localhost'
37
+
38
+ option :port,
39
+ description: 'Database port',
40
+ short: '-P PORT',
41
+ long: '--port PORT',
42
+ default: 5432
43
+
44
+ option :scheme,
45
+ description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
46
+ long: '--scheme SCHEME',
47
+ default: "#{Socket.gethostname}.postgresql"
48
+
49
+ def run
50
+ timestamp = Time.now.to_i
51
+
52
+ con = PG::Connection.new(config[:hostname], config[:port], nil, nil, 'postgres', config[:user], config[:password])
53
+ request = [
54
+ 'select checkpoints_timed, checkpoints_req,',
55
+ 'buffers_checkpoint, buffers_clean,',
56
+ 'maxwritten_clean, buffers_backend,',
57
+ 'buffers_alloc',
58
+ 'from pg_stat_bgwriter'
59
+ ]
60
+ con.exec(request.join(' ')) do |result|
61
+ result.each do |row|
62
+ output "#{config[:scheme]}.bgwriter.checkpoints_timed", row['checkpoints_timed'], timestamp
63
+ output "#{config[:scheme]}.bgwriter.checkpoints_req", row['checkpoints_req'], timestamp
64
+ output "#{config[:scheme]}.bgwriter.buffers_checkpoint", row['buffers_checkpoint'], timestamp
65
+ output "#{config[:scheme]}.bgwriter.buffers_clean", row['buffers_clean'], timestamp
66
+ output "#{config[:scheme]}.bgwriter.maxwritten_clean", row['maxwritten_clean'], timestamp
67
+ output "#{config[:scheme]}.bgwriter.buffers_backend", row['buffers_backend'], timestamp
68
+ output "#{config[:scheme]}.bgwriter.buffers_alloc", row['buffers_alloc'], timestamp
69
+ end
70
+ end
71
+
72
+ ok
73
+ end
74
+ end
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Postgres Stat DB Metrics
4
+ # ===
5
+ #
6
+ # Dependencies
7
+ # -----------
8
+ # - PSQL `track_counts` `track_io_timing` for some metrics enabled
9
+ # - Ruby gem `pg`
10
+ #
11
+ #
12
+ # Copyright 2012 Kwarter, Inc <platforms@kwarter.com>
13
+ # Author Gilles Devaux <gilles.devaux@gmail.com>
14
+ #
15
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
16
+ # for details.
17
+
18
+ require 'sensu-plugin/metric/cli'
19
+ require 'pg'
20
+ require 'socket'
21
+
22
+ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
23
+ option :user,
24
+ description: 'Postgres User',
25
+ short: '-u USER',
26
+ long: '--user USER'
27
+
28
+ option :password,
29
+ description: 'Postgres Password',
30
+ short: '-p PASS',
31
+ long: '--password PASS'
32
+
33
+ option :hostname,
34
+ description: 'Hostname to login to',
35
+ short: '-h HOST',
36
+ long: '--hostname HOST',
37
+ default: 'localhost'
38
+
39
+ option :port,
40
+ description: 'Database port',
41
+ short: '-P PORT',
42
+ long: '--port PORT',
43
+ default: 5432
44
+
45
+ option :db,
46
+ description: 'Database name',
47
+ short: '-d DB',
48
+ long: '--db DB',
49
+ default: 'postgres'
50
+
51
+ option :scheme,
52
+ description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
53
+ long: '--scheme SCHEME',
54
+ default: "#{Socket.gethostname}.postgresql"
55
+
56
+ def run
57
+ timestamp = Time.now.to_i
58
+
59
+ con = PG::Connection.new(config[:hostname], config[:port], nil, nil, 'postgres', config[:user], config[:password])
60
+ request = [
61
+ 'select xact_commit, xact_rollback,',
62
+ 'blks_read, blks_hit,',
63
+ 'tup_returned, tup_fetched, tup_inserted, tup_updated, tup_deleted',
64
+ "from pg_stat_database where datname='#{config[:db]}'"
65
+ ]
66
+ con.exec(request.join(' ')) do |result|
67
+ result.each do |row|
68
+ output "#{config[:scheme]}.statsdb.#{config[:db]}.xact_commit", row['xact_commit'], timestamp
69
+ output "#{config[:scheme]}.statsdb.#{config[:db]}.xact_rollback", row['xact_rollback'], timestamp
70
+ output "#{config[:scheme]}.statsdb.#{config[:db]}.blks_read", row['blks_read'], timestamp
71
+ output "#{config[:scheme]}.statsdb.#{config[:db]}.blks_hit", row['blks_hit'], timestamp
72
+ output "#{config[:scheme]}.statsdb.#{config[:db]}.tup_returned", row['tup_returned'], timestamp
73
+ output "#{config[:scheme]}.statsdb.#{config[:db]}.tup_fetched", row['tup_fetched'], timestamp
74
+ output "#{config[:scheme]}.statsdb.#{config[:db]}.tup_inserted", row['tup_inserted'], timestamp
75
+ output "#{config[:scheme]}.statsdb.#{config[:db]}.tup_updated", row['tup_updated'], timestamp
76
+ output "#{config[:scheme]}.statsdb.#{config[:db]}.tup_deleted", row['tup_deleted'], timestamp
77
+ end
78
+ end
79
+
80
+ ok
81
+ end
82
+ end
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Postgres StatIO Metrics
4
+ # ===
5
+ #
6
+ # Dependencies
7
+ # -----------
8
+ # - PSQL `track_io_timing` enabled
9
+ # - Ruby gem `pg`
10
+ #
11
+ #
12
+ # Copyright 2012 Kwarter, Inc <platforms@kwarter.com>
13
+ # Author Gilles Devaux <gilles.devaux@gmail.com>
14
+ #
15
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
16
+ # for details.
17
+
18
+ require 'sensu-plugin/metric/cli'
19
+ require 'pg'
20
+ require 'socket'
21
+
22
+ class PostgresStatsIOMetrics < Sensu::Plugin::Metric::CLI::Graphite
23
+ option :user,
24
+ description: 'Postgres User',
25
+ short: '-u USER',
26
+ long: '--user USER'
27
+
28
+ option :password,
29
+ description: 'Postgres Password',
30
+ short: '-p PASS',
31
+ long: '--password PASS'
32
+
33
+ option :hostname,
34
+ description: 'Hostname to login to',
35
+ short: '-h HOST',
36
+ long: '--hostname HOST',
37
+ default: 'localhost'
38
+
39
+ option :port,
40
+ description: 'Database port',
41
+ short: '-P PORT',
42
+ long: '--port PORT',
43
+ default: 5432
44
+
45
+ option :db,
46
+ description: 'Database name',
47
+ short: '-d DB',
48
+ long: '--db DB',
49
+ default: 'postgres'
50
+
51
+ option :scope,
52
+ description: 'Scope, see http://www.postgresql.org/docs/9.2/static/monitoring-stats.html',
53
+ short: '-s SCOPE',
54
+ long: '--scope SCOPE',
55
+ default: 'user'
56
+
57
+ option :scheme,
58
+ description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
59
+ long: '--scheme SCHEME',
60
+ default: "#{Socket.gethostname}.postgresql"
61
+
62
+ def run
63
+ timestamp = Time.now.to_i
64
+
65
+ con = PG::Connection.new(config[:hostname], config[:port], nil, nil, config[:db], config[:user], config[:password])
66
+ request = [
67
+ 'select sum(heap_blks_read) as heap_blks_read, sum(heap_blks_hit) as heap_blks_hit,',
68
+ 'sum(idx_blks_read) as idx_blks_read, sum(idx_blks_hit) as idx_blks_hit,',
69
+ 'sum(toast_blks_read) as toast_blks_read, sum(toast_blks_hit) as toast_blks_hit,',
70
+ 'sum(tidx_blks_read) as tidx_blks_read, sum(tidx_blks_hit) as tidx_blks_hit',
71
+ "from pg_statio_#{config[:scope]}_tables"
72
+ ]
73
+ con.exec(request.join(' ')) do |result|
74
+ result.each do |row|
75
+ output "#{config[:scheme]}.statsio.#{config[:db]}.heap_blks_read", row['heap_blks_read'], timestamp
76
+ output "#{config[:scheme]}.statsio.#{config[:db]}.heap_blks_hit", row['heap_blks_hit'], timestamp
77
+ output "#{config[:scheme]}.statsio.#{config[:db]}.idx_blks_read", row['idx_blks_read'], timestamp
78
+ output "#{config[:scheme]}.statsio.#{config[:db]}.idx_blks_hit", row['idx_blks_hit'], timestamp
79
+ output "#{config[:scheme]}.statsio.#{config[:db]}.toast_blks_read", row['toast_blks_read'], timestamp
80
+ output "#{config[:scheme]}.statsio.#{config[:db]}.toast_blks_hit", row['toast_blks_hit'], timestamp
81
+ output "#{config[:scheme]}.statsio.#{config[:db]}.tidx_blks_read", row['tidx_blks_read'], timestamp
82
+ output "#{config[:scheme]}.statsio.#{config[:db]}.tidx_blks_hit", row['tidx_blks_hit'], timestamp
83
+ end
84
+ end
85
+
86
+ ok
87
+ end
88
+ end
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Postgres Stat Table Metrics
4
+ # ===
5
+ #
6
+ # Dependencies
7
+ # -----------
8
+ # - PSQL `track_counts` enabled
9
+ # - Ruby gem `pg`
10
+ #
11
+ #
12
+ # Copyright 2012 Kwarter, Inc <platforms@kwarter.com>
13
+ # Author Gilles Devaux <gilles.devaux@gmail.com>
14
+ #
15
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
16
+ # for details.
17
+
18
+ require 'sensu-plugin/metric/cli'
19
+ require 'pg'
20
+ require 'socket'
21
+
22
+ class PostgresStatsTableMetrics < Sensu::Plugin::Metric::CLI::Graphite
23
+ option :user,
24
+ description: 'Postgres User',
25
+ short: '-u USER',
26
+ long: '--user USER'
27
+
28
+ option :password,
29
+ description: 'Postgres Password',
30
+ short: '-p PASS',
31
+ long: '--password PASS'
32
+
33
+ option :hostname,
34
+ description: 'Hostname to login to',
35
+ short: '-h HOST',
36
+ long: '--hostname HOST',
37
+ default: 'localhost'
38
+
39
+ option :port,
40
+ description: 'Database port',
41
+ short: '-P PORT',
42
+ long: '--port PORT',
43
+ default: 5432
44
+
45
+ option :db,
46
+ description: 'Database name',
47
+ short: '-d DB',
48
+ long: '--db DB',
49
+ default: 'postgres'
50
+
51
+ option :scope,
52
+ description: 'Scope, see http://www.postgresql.org/docs/9.2/static/monitoring-stats.html',
53
+ short: '-s SCOPE',
54
+ long: '--scope SCOPE',
55
+ default: 'user'
56
+
57
+ option :scheme,
58
+ description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
59
+ long: '--scheme SCHEME',
60
+ default: "#{Socket.gethostname}.postgresql"
61
+
62
+ def run # rubocop:disable all
63
+ timestamp = Time.now.to_i
64
+
65
+ con = PG::Connection.new(config[:hostname], config[:port], nil, nil, config[:db], config[:user], config[:password])
66
+ request = [
67
+ 'select sum(seq_scan) as seq_scan, sum(seq_tup_read) as seq_tup_read,',
68
+ 'sum(idx_scan) as idx_scan, sum(idx_tup_fetch) as idx_tup_fetch,',
69
+ 'sum(n_tup_ins) as n_tup_ins, sum(n_tup_upd) as n_tup_upd, sum(n_tup_del) as n_tup_del,',
70
+ 'sum(n_tup_hot_upd) as n_tup_hot_upd, sum(n_live_tup) as n_live_tup, sum(n_dead_tup) as n_dead_tup',
71
+ "from pg_stat_#{config[:scope]}_tables"
72
+ ]
73
+ con.exec(request.join(' ')) do |result|
74
+ result.each do |row|
75
+ output "#{config[:scheme]}.statstable.#{config[:db]}.seq_scan", row['seq_scan'], timestamp
76
+ output "#{config[:scheme]}.statstable.#{config[:db]}.seq_tup_read", row['seq_tup_read'], timestamp
77
+ output "#{config[:scheme]}.statstable.#{config[:db]}.idx_scan", row['idx_scan'], timestamp
78
+ output "#{config[:scheme]}.statstable.#{config[:db]}.idx_tup_fetch", row['idx_tup_fetch'], timestamp
79
+ output "#{config[:scheme]}.statstable.#{config[:db]}.n_tup_ins", row['n_tup_ins'], timestamp
80
+ output "#{config[:scheme]}.statstable.#{config[:db]}.n_tup_upd", row['n_tup_upd'], timestamp
81
+ output "#{config[:scheme]}.statstable.#{config[:db]}.n_tup_del", row['n_tup_del'], timestamp
82
+ output "#{config[:scheme]}.statstable.#{config[:db]}.n_tup_hot_upd", row['n_tup_hot_upd'], timestamp
83
+ output "#{config[:scheme]}.statstable.#{config[:db]}.n_live_tup", row['n_live_tup'], timestamp
84
+ output "#{config[:scheme]}.statstable.#{config[:db]}.n_dead_tup", row['n_dead_tup'], timestamp
85
+ end
86
+ end
87
+
88
+ ok
89
+ end
90
+ end
@@ -0,0 +1,2 @@
1
+
2
+ require 'sensu-plugins-postgres/version'
@@ -0,0 +1,13 @@
1
+ require 'json'
2
+
3
+ # encoding: utf-8
4
+ module SensuPluginsPostgres
5
+ # This defines the version of the gem
6
+ module Version
7
+ MAJOR = 0
8
+ MINOR = 0
9
+ PATCH = 1
10
+
11
+ VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,240 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-postgres
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sensu-Plugins and contributors
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDgDCCAmigAwIBAgIBATANBgkqhkiG9w0BAQUFADBDMRIwEAYDVQQDDAltYXR0
14
+ am9uZXMxGDAWBgoJkiaJk/IsZAEZFgh5aWVsZGJvdDETMBEGCgmSJomT8ixkARkW
15
+ A2NvbTAeFw0xNTAxMjgyMTAyNTFaFw0xNjAxMjgyMTAyNTFaMEMxEjAQBgNVBAMM
16
+ CW1hdHRqb25lczEYMBYGCgmSJomT8ixkARkWCHlpZWxkYm90MRMwEQYKCZImiZPy
17
+ LGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyTSzVYnO
18
+ CLgyrIyT1mBQakArQyW8xhi6MlDqyzXHJGeERT790U6EgoBVeS4XoK0ptFZNR8Tf
19
+ zko0w+Nv47TarSCgkPOaxY+mxWnAVR10dOmfeLr7huiMyps+YD56/EF2FqQ3jf/+
20
+ qohENfKD91qy1ieEy+Fn7Pf74ltbNKUdkb9a9eFXQ0DQ4ip5vik7DzjQkUTj4lca
21
+ k6ArwnmHX4YDhZoYtrQJ8jVktN0/+NtA40M5qkCYHNe5tUW25b/tKVYuioxG6b2Z
22
+ oIzaZxRLxf6HVAWpCVRT/F5+/yjigkX4u++eYacfLGleXQzoK7BL65vHGMJygWEE
23
+ 0TKGqFOrl/L0AQIDAQABo38wfTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
24
+ HQ4EFgQUEf6a8Td7MrSZc8ImbLFZAENPbz0wIQYDVR0RBBowGIEWbWF0dGpvbmVz
25
+ QHlpZWxkYm90LmNvbTAhBgNVHRIEGjAYgRZtYXR0am9uZXNAeWllbGRib3QuY29t
26
+ MA0GCSqGSIb3DQEBBQUAA4IBAQBbzXAYA3BVGw8DZ0YYoY1VHPNEcH5qPIApmHO8
27
+ rvSmuUT0yMEi7u00H/5uHRFf4LleGT/+sTdyXKsNPGT9kdRuQEgwi+vf7Zfvd8aX
28
+ UF/+4VkEYf/8rV8Ere6u2QaWPgApdMV6JjKr1fAwCTd8AuGXNaWItiPPMseSQzLJ
29
+ JKP4hVvbc1d+oS925B1lcBiqn2aYvElbyNAVmQPywNNqkWmvtlqj9ZVJfV5HQLdu
30
+ 8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
31
+ HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
32
+ -----END CERTIFICATE-----
33
+ date: 2015-05-31 00:00:00.000000000 Z
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: sensu-plugin
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.1.0
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '='
47
+ - !ruby/object:Gem::Version
48
+ version: 1.1.0
49
+ - !ruby/object:Gem::Dependency
50
+ name: pg
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '='
54
+ - !ruby/object:Gem::Version
55
+ version: 0.18.2
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '='
61
+ - !ruby/object:Gem::Version
62
+ version: 0.18.2
63
+ - !ruby/object:Gem::Dependency
64
+ name: codeclimate-test-reporter
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.4'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '0.4'
77
+ - !ruby/object:Gem::Dependency
78
+ name: rubocop
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '0.30'
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '0.30'
91
+ - !ruby/object:Gem::Dependency
92
+ name: rspec
93
+ requirement: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.1'
98
+ type: :development
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '3.1'
105
+ - !ruby/object:Gem::Dependency
106
+ name: bundler
107
+ requirement: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.7'
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '1.7'
119
+ - !ruby/object:Gem::Dependency
120
+ name: rake
121
+ requirement: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '10.0'
126
+ type: :development
127
+ prerelease: false
128
+ version_requirements: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '10.0'
133
+ - !ruby/object:Gem::Dependency
134
+ name: github-markup
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '1.3'
140
+ type: :development
141
+ prerelease: false
142
+ version_requirements: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '1.3'
147
+ - !ruby/object:Gem::Dependency
148
+ name: redcarpet
149
+ requirement: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '3.2'
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '3.2'
161
+ - !ruby/object:Gem::Dependency
162
+ name: yard
163
+ requirement: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '0.8'
168
+ type: :development
169
+ prerelease: false
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - "~>"
173
+ - !ruby/object:Gem::Version
174
+ version: '0.8'
175
+ - !ruby/object:Gem::Dependency
176
+ name: pry
177
+ requirement: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '0.10'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: '0.10'
189
+ description: Sensu plugins for postgres
190
+ email: "<sensu-users@googlegroups.com>"
191
+ executables: []
192
+ extensions: []
193
+ extra_rdoc_files: []
194
+ files:
195
+ - CHANGELOG.md
196
+ - LICENSE
197
+ - README.md
198
+ - bin/check-postgres-alive.rb
199
+ - bin/check-postgres-replication.rb
200
+ - bin/metric-postgres-connections.rb
201
+ - bin/metric-postgres-dbsize.rb
202
+ - bin/metric-postgres-graphite.rb
203
+ - bin/metric-postgres-locks.rb
204
+ - bin/metric-postgres-statsbgwriter.rb
205
+ - bin/metric-postgres-statsdb.rb
206
+ - bin/metric-postgres-statsio.rb
207
+ - bin/metric-postgres-statstable.rb
208
+ - lib/sensu-plugins-postgres.rb
209
+ - lib/sensu-plugins-postgres/version.rb
210
+ homepage: https://github.com/sensu-plugins/sensu-plugins-postgres
211
+ licenses:
212
+ - MIT
213
+ metadata:
214
+ maintainer: ''
215
+ development_status: active
216
+ production_status: unstable - testing recommended
217
+ release_draft: 'false'
218
+ release_prerelease: 'false'
219
+ post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
220
+ in /etc/default/sensu
221
+ rdoc_options: []
222
+ require_paths:
223
+ - lib
224
+ required_ruby_version: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - ">="
227
+ - !ruby/object:Gem::Version
228
+ version: 1.9.3
229
+ required_rubygems_version: !ruby/object:Gem::Requirement
230
+ requirements:
231
+ - - ">="
232
+ - !ruby/object:Gem::Version
233
+ version: '0'
234
+ requirements: []
235
+ rubyforge_project:
236
+ rubygems_version: 2.4.6
237
+ signing_key:
238
+ specification_version: 4
239
+ summary: Sensu plugins for postgres
240
+ test_files: []
metadata.gz.sig ADDED
@@ -0,0 +1,3 @@
1
+ �+a��������k&�g���ߓ)/�~����<g�锆+en���t�Lb
2
+ Y����?�;�A��~��^̷�(2��):^-�Կn#St>)����e�my��π4�\4���]�Hf
3
+ Z��.݁�������KwOuD��Q��4���>��xh����G�s����Wu \���M\�N��CEw�� ?j�l,ۓ���bP�2�7��:���^OLT��F0