sensu-plugins-postgres 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OTIyN2VhZjQwMWZhNzhlOGZjZDUyYjI4MWFiYmIzZGRhNGFmYzNiZA==
5
- data.tar.gz: !binary |-
6
- NDQ4ZGVhOGZlZDQ4MTFkZjdmMjU2NzgxNDM5YWUwNWMyYjNmNDEyNQ==
2
+ SHA1:
3
+ metadata.gz: c8bd7d42a4da5586cf9bc1feb0d93f7006603ccf
4
+ data.tar.gz: ca622f7c1882130abb6f5923cf7b9500284f4df7
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MzczNThmZmYwOGQwZDlkYzNmMjdhMjI2YzExNmNjYzdlMjNiZjhjMjc0MWYy
10
- MTc0NjQxNjk1MWQyZGY5Mzg5YzdiOGZmNTViMjJhMmQ3MGM3ZTgzOWY1NWFj
11
- YWFhZjQwNDFhYmRmYzY3NmMzYTY4ZTk3YTVkMWQ5ZWYyNDVmMjM=
12
- data.tar.gz: !binary |-
13
- MzY3Y2MwNzk1YWFkMjE2NWM3ZGM4N2Q5NDExMmNmMzk1ZGZlMTQ5OGUyOTg4
14
- N2RkODA1ZGNlMzg5MGI1MTZjZGY3MTgyNDk2MWFlMjFlMTJmNzc1ODhhOTRm
15
- NTc1ZTEwNjE5M2I4N2YxNjg2MzdlOTUxN2NkNjk1ZmNhZjczZjE=
6
+ metadata.gz: 675847f09f4ab9cd3cd0f86abf28df99c0396324dd8f1ef5da21c064ab8af23aa91fd26cc58a6b72fa0f4754f4883579ebf0d92ede19d666d61ad1858df33c95
7
+ data.tar.gz: 8d87a30589db442025420ee2c05961c29981c18f20b6344ac02c675d2023a51303de4a7d0b60c7b5bb5b9469f2999a9421c7df7218b38777c83aabc4f1e5aa6f
@@ -5,6 +5,17 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [1.0.0] - 2016-12-27
9
+ ### Fixed
10
+ - metric-postgres-connections: Handle postgres version 9.6 and above.
11
+
12
+ ### Removed
13
+ - Ruby 1.9.3 and 2.0.0 support
14
+
15
+ ### Added
16
+ - Ruby 2.3.0 support
17
+ - Update all the scripts to add an optional timeout setting.
18
+
8
19
  ## [0.1.1] - 2016-03-24
9
20
  ### Added
10
21
  - metric-postgres-connections: Add new metric `total`
@@ -51,7 +62,9 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
51
62
  ### Added
52
63
  - initial release
53
64
 
54
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/0.1.0...HEAD
65
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/1.0.0...HEAD
66
+ [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/0.1.1...1.0.0
67
+ [0.1.1]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/0.1.0...0.1.1
55
68
  [0.1.0]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/0.0.7...0.1.0
56
69
  [0.0.7]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/0.0.6...0.0.7
57
70
  [0.0.6]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/0.0.5...0.0.6
@@ -58,8 +58,18 @@ class CheckPostgres < Sensu::Plugin::Check::CLI
58
58
  long: '--port PORT',
59
59
  default: 5432
60
60
 
61
+ option :timeout,
62
+ description: 'Connection timeout (seconds)',
63
+ short: '-T TIMEOUT',
64
+ long: '--timeout TIMEOUT',
65
+ default: nil
66
+
61
67
  def run
62
- con = PG::Connection.new(config[:hostname], config[:port], nil, nil, config[:database], config[:user], config[:password])
68
+ con = PG.connect(host: config[:hostname],
69
+ dbname: config[:database],
70
+ user: config[:user],
71
+ password: config[:password],
72
+ connect_timeout: config[:timeout])
63
73
  res = con.exec('select version();')
64
74
  info = res.first
65
75
 
@@ -58,7 +58,7 @@ class CheckPostgresConnections < Sensu::Plugin::Check::CLI
58
58
  long: '--port PORT',
59
59
  default: 5432
60
60
 
61
- option :db,
61
+ option :database,
62
62
  description: 'Database name',
63
63
  short: '-d DB',
64
64
  long: '--db DB',
@@ -67,7 +67,7 @@ class CheckPostgresConnections < Sensu::Plugin::Check::CLI
67
67
  option :warning,
68
68
  description: 'Warning threshold number or % of connections. (default: 200 connections)',
69
69
  short: '-w WARNING',
70
- long: '--warning CRITICAL',
70
+ long: '--warning WARNING',
71
71
  default: 200,
72
72
  proc: proc(&:to_i)
73
73
 
@@ -85,9 +85,19 @@ class CheckPostgresConnections < Sensu::Plugin::Check::CLI
85
85
  boolean: true,
86
86
  default: false
87
87
 
88
+ option :timeout,
89
+ description: 'Connection timeout (seconds)',
90
+ short: '-T TIMEOUT',
91
+ long: '--timeout TIMEOUT',
92
+ default: nil
93
+
88
94
  def run
89
95
  begin
90
- con = PG::Connection.new(config[:hostname], config[:port], nil, nil, config[:db], config[:user], config[:password])
96
+ con = PG.connect(host: config[:hostname],
97
+ dbname: config[:database],
98
+ user: config[:user],
99
+ password: config[:password],
100
+ connect_timeout: config[:timeout])
91
101
  max_conns = con.exec('SHOW max_connections').getvalue(0, 0).to_i
92
102
  current_conns = con.exec('SELECT count(*) from pg_stat_activity').getvalue(0, 0).to_i
93
103
  rescue PG::Error => e
@@ -57,7 +57,7 @@ class CheckPostgresQuery < Sensu::Plugin::Check::CLI
57
57
  long: '--port PORT',
58
58
  default: 5432
59
59
 
60
- option :db,
60
+ option :database,
61
61
  description: 'Database name',
62
62
  short: '-d DB',
63
63
  long: '--db DB',
@@ -88,9 +88,19 @@ class CheckPostgresQuery < Sensu::Plugin::Check::CLI
88
88
  long: '--critical CRITICAL',
89
89
  default: nil
90
90
 
91
+ option :timeout,
92
+ description: 'Connection timeout (seconds)',
93
+ short: '-T TIMEOUT',
94
+ long: '--timeout TIMEOUT',
95
+ default: nil
96
+
91
97
  def run
92
98
  begin
93
- con = PG::Connection.new(config[:hostname], config[:port], nil, nil, config[:db], config[:user], config[:password])
99
+ con = PG.connect(host: config[:hostname],
100
+ dbname: config[:database],
101
+ user: config[:user],
102
+ password: config[:password],
103
+ connect_timeout: config[:timeout])
94
104
  res = con.exec(config[:query].to_s)
95
105
  rescue PG::Error => e
96
106
  unknown "Unable to query PostgreSQL: #{e.message}"
@@ -78,6 +78,12 @@ class CheckPostgresReplicationStatus < Sensu::Plugin::Check::CLI
78
78
  # #YELLOW
79
79
  proc: lambda { |s| s.to_i }) # rubocop:disable Lambda
80
80
 
81
+ option(:timeout,
82
+ short: '-T',
83
+ long: '--timeout',
84
+ default: nil,
85
+ description: 'Connection timeout (seconds)')
86
+
81
87
  def compute_lag(master, slave, m_segbytes)
82
88
  m_segment, m_offset = master.split('/')
83
89
  s_segment, s_offset = slave.split('/')
@@ -92,7 +98,8 @@ class CheckPostgresReplicationStatus < Sensu::Plugin::Check::CLI
92
98
  dbname: config[:database],
93
99
  user: config[:user],
94
100
  password: config[:password],
95
- sslmode: ssl_mode)
101
+ sslmode: ssl_mode,
102
+ connect_timeout: config[:timeout])
96
103
 
97
104
  master = conn_master.exec('SELECT pg_current_xlog_location()').getvalue(0, 0)
98
105
  m_segbytes = conn_master.exec('SHOW wal_segment_size').getvalue(0, 0).sub(/\D+/, '').to_i << 20
@@ -103,7 +110,8 @@ class CheckPostgresReplicationStatus < Sensu::Plugin::Check::CLI
103
110
  dbname: config[:database],
104
111
  user: config[:user],
105
112
  password: config[:password],
106
- sslmode: ssl_mode)
113
+ sslmode: ssl_mode,
114
+ connect_timeout: config[:timeout])
107
115
 
108
116
  slave = conn_slave.exec('SELECT pg_last_xlog_receive_location()').getvalue(0, 0)
109
117
  conn_slave.close
@@ -114,10 +122,9 @@ class CheckPostgresReplicationStatus < Sensu::Plugin::Check::CLI
114
122
 
115
123
  message = "replication delayed by #{lag_in_mb}MB :: master:#{master} slave:#{slave} m_segbytes:#{m_segbytes}"
116
124
 
117
- case
118
- when lag_in_mb >= config[:crit]
125
+ if lag_in_mb >= config[:crit]
119
126
  critical message
120
- when lag_in_mb >= config[:warn]
127
+ elsif lag_in_mb >= config[:warn]
121
128
  warning message
122
129
  else
123
130
  ok message
@@ -55,7 +55,7 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
55
55
  long: '--port PORT',
56
56
  default: 5432
57
57
 
58
- option :db,
58
+ option :database,
59
59
  description: 'Database name',
60
60
  short: '-d DB',
61
61
  long: '--db DB',
@@ -66,13 +66,32 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
66
66
  long: '--scheme SCHEME',
67
67
  default: "#{Socket.gethostname}.postgresql"
68
68
 
69
+ option :timeout,
70
+ description: 'Connection timeout (seconds)',
71
+ short: '-T TIMEOUT',
72
+ long: '--timeout TIMEOUT',
73
+ default: nil
74
+
69
75
  def run
70
76
  timestamp = Time.now.to_i
71
77
 
72
- con = PG::Connection.new(config[:hostname], config[:port], nil, nil, 'postgres', config[:user], config[:password])
78
+ con = PG.connect(host: config[:hostname],
79
+ dbname: config[:database],
80
+ user: config[:user],
81
+ password: config[:password],
82
+ connect_timeout: config[:timeout])
83
+ request = [
84
+ "select case when count(*) = 1 then 'waiting' else",
85
+ "'case when wait_event_type is null then false else true end' end as wait_col",
86
+ 'from information_schema.columns',
87
+ "where table_name = 'pg_stat_activity' and table_schema = 'pg_catalog'",
88
+ "and column_name = 'waiting'"
89
+ ]
90
+ wait_col = con.exec(request.join(' ')).first['wait_col']
91
+
73
92
  request = [
74
- 'select count(*), waiting from pg_stat_activity',
75
- "where datname = '#{config[:db]}' group by waiting"
93
+ "select count(*), #{wait_col} as waiting from pg_stat_activity",
94
+ "where datname = '#{config[:database]}' group by #{wait_col}"
76
95
  ]
77
96
 
78
97
  metrics = {
@@ -93,7 +112,7 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
93
112
  metrics[:total] = (metrics[:waiting].to_i + metrics[:active].to_i)
94
113
 
95
114
  metrics.each do |metric, value|
96
- output "#{config[:scheme]}.connections.#{config[:db]}.#{metric}", value, timestamp
115
+ output "#{config[:scheme]}.connections.#{config[:database]}.#{metric}", value, timestamp
97
116
  end
98
117
 
99
118
  ok
@@ -55,7 +55,7 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
55
55
  long: '--port PORT',
56
56
  default: 5432
57
57
 
58
- option :db,
58
+ option :database,
59
59
  description: 'Database name',
60
60
  short: '-d DB',
61
61
  long: '--db DB',
@@ -66,17 +66,27 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
66
66
  long: '--scheme SCHEME',
67
67
  default: "#{Socket.gethostname}.postgresql"
68
68
 
69
+ option :timeout,
70
+ description: 'Connection timeout (seconds)',
71
+ short: '-T TIMEOUT',
72
+ long: '--timeout TIMEOUT',
73
+ default: nil
74
+
69
75
  def run
70
76
  timestamp = Time.now.to_i
71
77
 
72
- con = PG::Connection.new(config[:hostname], config[:port], nil, nil, 'postgres', config[:user], config[:password])
78
+ con = PG.connect(host: config[:hostname],
79
+ dbname: config[:database],
80
+ user: config[:user],
81
+ password: config[:password],
82
+ connect_timeout: config[:timeout])
73
83
  request = [
74
- "select pg_database_size('#{config[:db]}')"
84
+ "select pg_database_size('#{config[:database]}')"
75
85
  ]
76
86
 
77
87
  con.exec(request.join(' ')) do |result|
78
88
  result.each do |row|
79
- output "#{config[:scheme]}.size.#{config[:db]}", row['pg_database_size'], timestamp
89
+ output "#{config[:scheme]}.size.#{config[:database]}", row['pg_database_size'], timestamp
80
90
  end
81
91
  end
82
92
 
@@ -70,16 +70,19 @@ class CheckpostgresReplicationStatus < Sensu::Plugin::Metric::CLI::Graphite
70
70
  long: '--port PORT',
71
71
  default: 5432
72
72
 
73
- def run
74
- @dbmaster = config[:master_host]
75
- @dbslave = config[:slave_host]
76
- @dbport = config[:port]
77
- @dbname = config[:database]
78
- @dbusername = config[:user]
79
- @password = config[:pass]
73
+ option :timeout,
74
+ description: 'Connection timeout (seconds)',
75
+ short: '-T TIMEOUT',
76
+ long: '--timeout TIMEOUT',
77
+ default: nil
80
78
 
79
+ def run
81
80
  # Establishing connections to the master
82
- conn_master = PGconn.connect(@dbmaster, @dbport, '', '', @dbname, @dbusername, @password)
81
+ conn_master = PG.connect(host: config[:master_host],
82
+ dbname: config[:database],
83
+ user: config[:user],
84
+ password: config[:password],
85
+ connect_timeout: config[:timeout])
83
86
  res1 = conn_master.exec('SELECT pg_current_xlog_location()').getvalue(0, 0)
84
87
  m_segbytes = conn_master.exec('SHOW wal_segment_size').getvalue(0, 0).sub(/\D+/, '').to_i << 20
85
88
  conn_master.close
@@ -91,7 +94,11 @@ class CheckpostgresReplicationStatus < Sensu::Plugin::Metric::CLI::Graphite
91
94
  end
92
95
 
93
96
  # Establishing connections to the slave
94
- conn_slave = PGconn.connect(@dbslave, @dbport, '', '', @dbname, @dbusername, @password)
97
+ conn_slave = PG.connect(host: config[:slave_host],
98
+ dbname: config[:database],
99
+ user: config[:user],
100
+ password: config[:password],
101
+ connect_timeout: config[:timeout])
95
102
  res = conn_slave.exec('SELECT pg_last_xlog_receive_location()').getvalue(0, 0)
96
103
  conn_slave.close
97
104
 
@@ -55,7 +55,7 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
55
55
  long: '--port PORT',
56
56
  default: 5432
57
57
 
58
- option :db,
58
+ option :database,
59
59
  description: 'Database name',
60
60
  short: '-d DB',
61
61
  long: '--db DB',
@@ -66,15 +66,25 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
66
66
  long: '--scheme SCHEME',
67
67
  default: "#{Socket.gethostname}.postgresql"
68
68
 
69
+ option :timeout,
70
+ description: 'Connection timeout (seconds)',
71
+ short: '-T TIMEOUT',
72
+ long: '--timeout TIMEOUT',
73
+ default: nil
74
+
69
75
  def run
70
76
  timestamp = Time.now.to_i
71
77
 
72
78
  locks_per_type = Hash.new(0)
73
79
 
74
- con = PG::Connection.new(config[:hostname], config[:port], nil, nil, 'postgres', config[:user], config[:password])
80
+ con = PG.connect(host: config[:hostname],
81
+ dbname: config[:database],
82
+ user: config[:user],
83
+ password: config[:password],
84
+ connect_timeout: config[:timeout])
75
85
  request = [
76
86
  'SELECT mode, count(mode) FROM pg_locks',
77
- "where database = (select oid from pg_database where datname = '#{config[:db]}')",
87
+ "where database = (select oid from pg_database where datname = '#{config[:database]}')",
78
88
  'group by mode'
79
89
  ]
80
90
 
@@ -86,7 +96,7 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
86
96
  end
87
97
 
88
98
  locks_per_type.each do |lock_type, count|
89
- output "#{config[:scheme]}.locks.#{config[:db]}.#{lock_type}", count, timestamp
99
+ output "#{config[:scheme]}.locks.#{config[:database]}.#{lock_type}", count, timestamp
90
100
  end
91
101
 
92
102
  ok
@@ -60,10 +60,20 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
60
60
  long: '--scheme SCHEME',
61
61
  default: "#{Socket.gethostname}.postgresql"
62
62
 
63
+ option :timeout,
64
+ description: 'Connection timeout (seconds)',
65
+ short: '-T TIMEOUT',
66
+ long: '--timeout TIMEOUT',
67
+ default: nil
68
+
63
69
  def run
64
70
  timestamp = Time.now.to_i
65
71
 
66
- con = PG::Connection.new(config[:hostname], config[:port], nil, nil, 'postgres', config[:user], config[:password])
72
+ con = PG.connect(host: config[:hostname],
73
+ dbname: 'postgres',
74
+ user: config[:user],
75
+ password: config[:password],
76
+ connect_timeout: config[:timeout])
67
77
  request = [
68
78
  'select checkpoints_timed, checkpoints_req,',
69
79
  'buffers_checkpoint, buffers_clean,',
@@ -56,7 +56,7 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
56
56
  long: '--port PORT',
57
57
  default: 5432
58
58
 
59
- option :db,
59
+ option :database,
60
60
  description: 'Database name',
61
61
  short: '-d DB',
62
62
  long: '--db DB',
@@ -67,27 +67,37 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
67
67
  long: '--scheme SCHEME',
68
68
  default: "#{Socket.gethostname}.postgresql"
69
69
 
70
+ option :timeout,
71
+ description: 'Connection timeout (seconds)',
72
+ short: '-T TIMEOUT',
73
+ long: '--timeout TIMEOUT',
74
+ default: nil
75
+
70
76
  def run
71
77
  timestamp = Time.now.to_i
72
78
 
73
- con = PG::Connection.new(config[:hostname], config[:port], nil, nil, 'postgres', config[:user], config[:password])
79
+ con = PG.connect(host: config[:hostname],
80
+ dbname: config[:database],
81
+ user: config[:user],
82
+ password: config[:password],
83
+ connect_timeout: config[:timeout])
74
84
  request = [
75
85
  'select xact_commit, xact_rollback,',
76
86
  'blks_read, blks_hit,',
77
87
  'tup_returned, tup_fetched, tup_inserted, tup_updated, tup_deleted',
78
- "from pg_stat_database where datname='#{config[:db]}'"
88
+ "from pg_stat_database where datname='#{config[:database]}'"
79
89
  ]
80
90
  con.exec(request.join(' ')) do |result|
81
91
  result.each do |row|
82
- output "#{config[:scheme]}.statsdb.#{config[:db]}.xact_commit", row['xact_commit'], timestamp
83
- output "#{config[:scheme]}.statsdb.#{config[:db]}.xact_rollback", row['xact_rollback'], timestamp
84
- output "#{config[:scheme]}.statsdb.#{config[:db]}.blks_read", row['blks_read'], timestamp
85
- output "#{config[:scheme]}.statsdb.#{config[:db]}.blks_hit", row['blks_hit'], timestamp
86
- output "#{config[:scheme]}.statsdb.#{config[:db]}.tup_returned", row['tup_returned'], timestamp
87
- output "#{config[:scheme]}.statsdb.#{config[:db]}.tup_fetched", row['tup_fetched'], timestamp
88
- output "#{config[:scheme]}.statsdb.#{config[:db]}.tup_inserted", row['tup_inserted'], timestamp
89
- output "#{config[:scheme]}.statsdb.#{config[:db]}.tup_updated", row['tup_updated'], timestamp
90
- output "#{config[:scheme]}.statsdb.#{config[:db]}.tup_deleted", row['tup_deleted'], timestamp
92
+ output "#{config[:scheme]}.statsdb.#{config[:database]}.xact_commit", row['xact_commit'], timestamp
93
+ output "#{config[:scheme]}.statsdb.#{config[:database]}.xact_rollback", row['xact_rollback'], timestamp
94
+ output "#{config[:scheme]}.statsdb.#{config[:database]}.blks_read", row['blks_read'], timestamp
95
+ output "#{config[:scheme]}.statsdb.#{config[:database]}.blks_hit", row['blks_hit'], timestamp
96
+ output "#{config[:scheme]}.statsdb.#{config[:database]}.tup_returned", row['tup_returned'], timestamp
97
+ output "#{config[:scheme]}.statsdb.#{config[:database]}.tup_fetched", row['tup_fetched'], timestamp
98
+ output "#{config[:scheme]}.statsdb.#{config[:database]}.tup_inserted", row['tup_inserted'], timestamp
99
+ output "#{config[:scheme]}.statsdb.#{config[:database]}.tup_updated", row['tup_updated'], timestamp
100
+ output "#{config[:scheme]}.statsdb.#{config[:database]}.tup_deleted", row['tup_deleted'], timestamp
91
101
  end
92
102
  end
93
103
 
@@ -56,7 +56,7 @@ class PostgresStatsIOMetrics < Sensu::Plugin::Metric::CLI::Graphite
56
56
  long: '--port PORT',
57
57
  default: 5432
58
58
 
59
- option :db,
59
+ option :database,
60
60
  description: 'Database name',
61
61
  short: '-d DB',
62
62
  long: '--db DB',
@@ -73,10 +73,20 @@ class PostgresStatsIOMetrics < Sensu::Plugin::Metric::CLI::Graphite
73
73
  long: '--scheme SCHEME',
74
74
  default: "#{Socket.gethostname}.postgresql"
75
75
 
76
+ option :timeout,
77
+ description: 'Connection timeout (seconds)',
78
+ short: '-T TIMEOUT',
79
+ long: '--timeout TIMEOUT',
80
+ default: nil
81
+
76
82
  def run
77
83
  timestamp = Time.now.to_i
78
84
 
79
- con = PG::Connection.new(config[:hostname], config[:port], nil, nil, config[:db], config[:user], config[:password])
85
+ con = PG.connect(host: config[:hostname],
86
+ dbname: config[:database],
87
+ user: config[:user],
88
+ password: config[:password],
89
+ connect_timeout: config[:timeout])
80
90
  request = [
81
91
  'select sum(heap_blks_read) as heap_blks_read, sum(heap_blks_hit) as heap_blks_hit,',
82
92
  'sum(idx_blks_read) as idx_blks_read, sum(idx_blks_hit) as idx_blks_hit,',
@@ -86,14 +96,14 @@ class PostgresStatsIOMetrics < Sensu::Plugin::Metric::CLI::Graphite
86
96
  ]
87
97
  con.exec(request.join(' ')) do |result|
88
98
  result.each do |row|
89
- output "#{config[:scheme]}.statsio.#{config[:db]}.heap_blks_read", row['heap_blks_read'], timestamp
90
- output "#{config[:scheme]}.statsio.#{config[:db]}.heap_blks_hit", row['heap_blks_hit'], timestamp
91
- output "#{config[:scheme]}.statsio.#{config[:db]}.idx_blks_read", row['idx_blks_read'], timestamp
92
- output "#{config[:scheme]}.statsio.#{config[:db]}.idx_blks_hit", row['idx_blks_hit'], timestamp
93
- output "#{config[:scheme]}.statsio.#{config[:db]}.toast_blks_read", row['toast_blks_read'], timestamp
94
- output "#{config[:scheme]}.statsio.#{config[:db]}.toast_blks_hit", row['toast_blks_hit'], timestamp
95
- output "#{config[:scheme]}.statsio.#{config[:db]}.tidx_blks_read", row['tidx_blks_read'], timestamp
96
- output "#{config[:scheme]}.statsio.#{config[:db]}.tidx_blks_hit", row['tidx_blks_hit'], timestamp
99
+ output "#{config[:scheme]}.statsio.#{config[:database]}.heap_blks_read", row['heap_blks_read'], timestamp
100
+ output "#{config[:scheme]}.statsio.#{config[:database]}.heap_blks_hit", row['heap_blks_hit'], timestamp
101
+ output "#{config[:scheme]}.statsio.#{config[:database]}.idx_blks_read", row['idx_blks_read'], timestamp
102
+ output "#{config[:scheme]}.statsio.#{config[:database]}.idx_blks_hit", row['idx_blks_hit'], timestamp
103
+ output "#{config[:scheme]}.statsio.#{config[:database]}.toast_blks_read", row['toast_blks_read'], timestamp
104
+ output "#{config[:scheme]}.statsio.#{config[:database]}.toast_blks_hit", row['toast_blks_hit'], timestamp
105
+ output "#{config[:scheme]}.statsio.#{config[:database]}.tidx_blks_read", row['tidx_blks_read'], timestamp
106
+ output "#{config[:scheme]}.statsio.#{config[:database]}.tidx_blks_hit", row['tidx_blks_hit'], timestamp
97
107
  end
98
108
  end
99
109
 
@@ -56,7 +56,7 @@ class PostgresStatsTableMetrics < Sensu::Plugin::Metric::CLI::Graphite
56
56
  long: '--port PORT',
57
57
  default: 5432
58
58
 
59
- option :db,
59
+ option :database,
60
60
  description: 'Database name',
61
61
  short: '-d DB',
62
62
  long: '--db DB',
@@ -73,10 +73,20 @@ class PostgresStatsTableMetrics < Sensu::Plugin::Metric::CLI::Graphite
73
73
  long: '--scheme SCHEME',
74
74
  default: "#{Socket.gethostname}.postgresql"
75
75
 
76
+ option :timeout,
77
+ description: 'Connection timeout (seconds)',
78
+ short: '-T TIMEOUT',
79
+ long: '--timeout TIMEOUT',
80
+ default: nil
81
+
76
82
  def run
77
83
  timestamp = Time.now.to_i
78
84
 
79
- con = PG::Connection.new(config[:hostname], config[:port], nil, nil, config[:db], config[:user], config[:password])
85
+ con = PG.connect(host: config[:hostname],
86
+ dbname: config[:database],
87
+ user: config[:user],
88
+ password: config[:password],
89
+ connect_timeout: config[:timeout])
80
90
  request = [
81
91
  'select sum(seq_scan) as seq_scan, sum(seq_tup_read) as seq_tup_read,',
82
92
  'sum(idx_scan) as idx_scan, sum(idx_tup_fetch) as idx_tup_fetch,',
@@ -86,16 +96,16 @@ class PostgresStatsTableMetrics < Sensu::Plugin::Metric::CLI::Graphite
86
96
  ]
87
97
  con.exec(request.join(' ')) do |result|
88
98
  result.each do |row|
89
- output "#{config[:scheme]}.statstable.#{config[:db]}.seq_scan", row['seq_scan'], timestamp
90
- output "#{config[:scheme]}.statstable.#{config[:db]}.seq_tup_read", row['seq_tup_read'], timestamp
91
- output "#{config[:scheme]}.statstable.#{config[:db]}.idx_scan", row['idx_scan'], timestamp
92
- output "#{config[:scheme]}.statstable.#{config[:db]}.idx_tup_fetch", row['idx_tup_fetch'], timestamp
93
- output "#{config[:scheme]}.statstable.#{config[:db]}.n_tup_ins", row['n_tup_ins'], timestamp
94
- output "#{config[:scheme]}.statstable.#{config[:db]}.n_tup_upd", row['n_tup_upd'], timestamp
95
- output "#{config[:scheme]}.statstable.#{config[:db]}.n_tup_del", row['n_tup_del'], timestamp
96
- output "#{config[:scheme]}.statstable.#{config[:db]}.n_tup_hot_upd", row['n_tup_hot_upd'], timestamp
97
- output "#{config[:scheme]}.statstable.#{config[:db]}.n_live_tup", row['n_live_tup'], timestamp
98
- output "#{config[:scheme]}.statstable.#{config[:db]}.n_dead_tup", row['n_dead_tup'], timestamp
99
+ output "#{config[:scheme]}.statstable.#{config[:database]}.seq_scan", row['seq_scan'], timestamp
100
+ output "#{config[:scheme]}.statstable.#{config[:database]}.seq_tup_read", row['seq_tup_read'], timestamp
101
+ output "#{config[:scheme]}.statstable.#{config[:database]}.idx_scan", row['idx_scan'], timestamp
102
+ output "#{config[:scheme]}.statstable.#{config[:database]}.idx_tup_fetch", row['idx_tup_fetch'], timestamp
103
+ output "#{config[:scheme]}.statstable.#{config[:database]}.n_tup_ins", row['n_tup_ins'], timestamp
104
+ output "#{config[:scheme]}.statstable.#{config[:database]}.n_tup_upd", row['n_tup_upd'], timestamp
105
+ output "#{config[:scheme]}.statstable.#{config[:database]}.n_tup_del", row['n_tup_del'], timestamp
106
+ output "#{config[:scheme]}.statstable.#{config[:database]}.n_tup_hot_upd", row['n_tup_hot_upd'], timestamp
107
+ output "#{config[:scheme]}.statstable.#{config[:database]}.n_live_tup", row['n_live_tup'], timestamp
108
+ output "#{config[:scheme]}.statstable.#{config[:database]}.n_dead_tup", row['n_dead_tup'], timestamp
99
109
  end
100
110
  end
101
111
 
@@ -53,7 +53,7 @@ class MetricsPostgresQuery < Sensu::Plugin::Metric::CLI::Graphite
53
53
  long: '--port PORT',
54
54
  default: 5432
55
55
 
56
- option :db,
56
+ option :database,
57
57
  description: 'Database name',
58
58
  short: '-d DB',
59
59
  long: '--db DB',
@@ -78,9 +78,19 @@ class MetricsPostgresQuery < Sensu::Plugin::Metric::CLI::Graphite
78
78
  long: '--scheme SCHEME',
79
79
  default: 'postgres'
80
80
 
81
+ option :timeout,
82
+ description: 'Connection timeout (seconds)',
83
+ short: '-T TIMEOUT',
84
+ long: '--timeout TIMEOUT',
85
+ default: nil
86
+
81
87
  def run
82
88
  begin
83
- con = PG::Connection.new(config[:hostname], config[:port], nil, nil, config[:db], config[:user], config[:password])
89
+ con = PG.connect(host: config[:hostname],
90
+ dbname: config[:database],
91
+ user: config[:user],
92
+ password: config[:password],
93
+ connect_timeout: config[:timeout])
84
94
  res = con.exec(config[:query].to_s)
85
95
  rescue PG::Error => e
86
96
  unknown "Unable to query PostgreSQL: #{e.message}"
@@ -1,8 +1,8 @@
1
1
  module SensuPluginsPostgres
2
2
  module Version
3
- MAJOR = 0
4
- MINOR = 1
5
- PATCH = 1
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.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: 2016-03-25 00:00:00.000000000 Z
11
+ date: 2016-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.2'
27
27
  - !ruby/object:Gem::Dependency
@@ -56,134 +56,150 @@ dependencies:
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.7'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.7'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: codeclimate-test-reporter
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.4'
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
82
  version: '0.4'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: github-markup
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '1.3'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.3'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pry
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0.10'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.10'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rainbow
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 2.1.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 2.1.0
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rake
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - ~>
129
+ - - "~>"
116
130
  - !ruby/object:Gem::Version
117
131
  version: '10.0'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - ~>
136
+ - - "~>"
123
137
  - !ruby/object:Gem::Version
124
138
  version: '10.0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: redcarpet
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - ~>
143
+ - - "~>"
130
144
  - !ruby/object:Gem::Version
131
145
  version: '3.2'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - ~>
150
+ - - "~>"
137
151
  - !ruby/object:Gem::Version
138
152
  version: '3.2'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: rspec
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - ~>
157
+ - - "~>"
144
158
  - !ruby/object:Gem::Version
145
159
  version: '3.1'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - ~>
164
+ - - "~>"
151
165
  - !ruby/object:Gem::Version
152
166
  version: '3.1'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rubocop
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
- - - '='
171
+ - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: 0.34.2
173
+ version: 0.40.0
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
- - - '='
178
+ - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: 0.34.2
180
+ version: 0.40.0
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: yard
169
183
  requirement: !ruby/object:Gem::Requirement
170
184
  requirements:
171
- - - ~>
185
+ - - "~>"
172
186
  - !ruby/object:Gem::Version
173
187
  version: '0.8'
174
188
  type: :development
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
- - - ~>
192
+ - - "~>"
179
193
  - !ruby/object:Gem::Version
180
194
  version: '0.8'
181
- description: ! "This plugin provides native PostgreSQL\n instrumentation
182
- for monitoring and metrics\n collection, including:
183
- service health, database\n connectivity, database locks,
184
- replication status,\n database size, `pg_stat_bgwriter`
185
- metrics, and\n more."
186
- email: <sensu-users@googlegroups.com>
195
+ description: |-
196
+ This plugin provides native PostgreSQL
197
+ instrumentation for monitoring and metrics
198
+ collection, including: service health, database
199
+ connectivity, database locks, replication status,
200
+ database size, `pg_stat_bgwriter` metrics, and
201
+ more.
202
+ email: "<sensu-users@googlegroups.com>"
187
203
  executables:
188
204
  - check-postgres-alive.rb
189
205
  - check-postgres-connections.rb
@@ -223,7 +239,7 @@ homepage: https://github.com/sensu-plugins/sensu-plugins-postgres
223
239
  licenses:
224
240
  - MIT
225
241
  metadata:
226
- maintainer: ! '@tas50'
242
+ maintainer: "@tas50"
227
243
  development_status: active
228
244
  production_status: unstable - testing recommended
229
245
  release_draft: 'false'
@@ -235,12 +251,12 @@ require_paths:
235
251
  - lib
236
252
  required_ruby_version: !ruby/object:Gem::Requirement
237
253
  requirements:
238
- - - ! '>='
254
+ - - ">="
239
255
  - !ruby/object:Gem::Version
240
- version: 1.9.3
256
+ version: 2.1.0
241
257
  required_rubygems_version: !ruby/object:Gem::Requirement
242
258
  requirements:
243
- - - ! '>='
259
+ - - ">="
244
260
  - !ruby/object:Gem::Version
245
261
  version: '0'
246
262
  requirements: []