sensu-plugins-postgres 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +7 -2
- data/README.md +2 -0
- data/bin/check-postgres-alive.rb +24 -6
- data/bin/check-postgres-query.rb +114 -0
- data/bin/check-postgres-replication.rb +27 -1
- data/bin/metric-postgres-connections.rb +24 -10
- data/bin/metric-postgres-dbsize.rb +24 -10
- data/bin/metric-postgres-graphite.rb +27 -1
- data/bin/metric-postgres-locks.rb +24 -10
- data/bin/metric-postgres-statsbgwriter.rb +24 -10
- data/bin/metric-postgres-statsdb.rb +25 -11
- data/bin/metric-postgres-statsio.rb +25 -11
- data/bin/metric-postgres-statstable.rb +25 -11
- data/bin/metrics-postgres-query.rb +98 -0
- data/lib/sensu-plugins-postgres/version.rb +1 -1
- metadata +22 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7432563f70c59b745e34559e6d58844600a547b1
|
4
|
+
data.tar.gz: fbfd4cdbd878c065217450e3eb55f1bcf88f72e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac24ac7ab6da0069be23a23fb2b5b73372be1c97da058c18c86730cff23bce6fd3707be6fb8f0ab116ba7b1fde6880acf563111d951b6396ab11e6af635bb18c
|
7
|
+
data.tar.gz: 46cb43f2a13a044a0f8e86c7bd4d2ac7567784ce83e6cb7ae5b42cd659e5a841dc5c58cbb71d1293e15981ee49f926b7411e9e92594352b4a47c1b5df8d66005
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -3,12 +3,17 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
3
3
|
|
4
4
|
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
5
|
|
6
|
-
##
|
6
|
+
## [0.0.6] - 2015-10-08
|
7
|
+
### Changed
|
8
|
+
- standardized headers
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- added plugins for querying postgres
|
7
12
|
|
8
13
|
## [0.0.5] - 2015-10-06
|
9
14
|
### Changed
|
10
15
|
- updated pg gem to 0.18.3
|
11
|
-
Added port cli option to postgres-graphite.rb.
|
16
|
+
- Added port cli option to postgres-graphite.rb.
|
12
17
|
|
13
18
|
## [0.0.4] - 2015-08-04
|
14
19
|
### Changed
|
data/README.md
CHANGED
data/bin/check-postgres-alive.rb
CHANGED
@@ -1,13 +1,31 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
2
|
#
|
3
|
-
#
|
3
|
+
# check-postgres-alive
|
4
4
|
#
|
5
|
-
#
|
5
|
+
# DESCRIPTION:
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# This plugin attempts to login to postgres with provided credentials.
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# plain text
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: pg
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./check-postgres-alive.rb -u db_user -p db_pass -h db_host -d db
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Copyright (c) 2012 Lewis Preson & Tom Bassindale
|
26
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
27
|
+
# for details.
|
8
28
|
#
|
9
|
-
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
10
|
-
# for details.
|
11
29
|
|
12
30
|
require 'sensu-plugin/check/cli'
|
13
31
|
require 'pg'
|
@@ -0,0 +1,114 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-postgres-query
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin queries a PostgreSQL database. It alerts when the numeric
|
7
|
+
# result hits a threshold. Can optionally alert on the number of tuples
|
8
|
+
# (rows) returned by the query.
|
9
|
+
#
|
10
|
+
# OUTPUT:
|
11
|
+
# plain-text
|
12
|
+
#
|
13
|
+
# PLATFORMS:
|
14
|
+
# Linux
|
15
|
+
#
|
16
|
+
# DEPENDENCIES:
|
17
|
+
# gem: pg
|
18
|
+
# gem: sensu-plugin
|
19
|
+
# gem: dentaku
|
20
|
+
#
|
21
|
+
# USAGE:
|
22
|
+
# check-postgres-query.rb -u db_user -p db_pass -h db_host -d db -q 'select foo from bar' -w 'value > 5' -c 'value > 10'
|
23
|
+
#
|
24
|
+
# NOTES:
|
25
|
+
#
|
26
|
+
# LICENSE:
|
27
|
+
# Copyright 2015, Eric Heydrick <eheydrick@gmail.com>
|
28
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
29
|
+
# for details.
|
30
|
+
#
|
31
|
+
|
32
|
+
require 'sensu-plugin/check/cli'
|
33
|
+
require 'pg'
|
34
|
+
require 'dentaku'
|
35
|
+
|
36
|
+
# Check PostgresSQL Query
|
37
|
+
class CheckPostgresQuery < Sensu::Plugin::Check::CLI
|
38
|
+
option :user,
|
39
|
+
description: 'Postgres User',
|
40
|
+
short: '-u USER',
|
41
|
+
long: '--user USER'
|
42
|
+
|
43
|
+
option :password,
|
44
|
+
description: 'Postgres Password',
|
45
|
+
short: '-p PASS',
|
46
|
+
long: '--password PASS'
|
47
|
+
|
48
|
+
option :hostname,
|
49
|
+
description: 'Hostname to login to',
|
50
|
+
short: '-h HOST',
|
51
|
+
long: '--hostname HOST',
|
52
|
+
default: 'localhost'
|
53
|
+
|
54
|
+
option :port,
|
55
|
+
description: 'Database port',
|
56
|
+
short: '-P PORT',
|
57
|
+
long: '--port PORT',
|
58
|
+
default: 5432
|
59
|
+
|
60
|
+
option :db,
|
61
|
+
description: 'Database name',
|
62
|
+
short: '-d DB',
|
63
|
+
long: '--db DB',
|
64
|
+
default: 'postgres'
|
65
|
+
|
66
|
+
option :query,
|
67
|
+
description: 'Database query to execute',
|
68
|
+
short: '-q QUERY',
|
69
|
+
long: '--query QUERY',
|
70
|
+
required: true
|
71
|
+
|
72
|
+
option :check_tuples,
|
73
|
+
description: 'Check against the number of tuples (rows) returned by the query',
|
74
|
+
short: '-t',
|
75
|
+
long: '--tuples',
|
76
|
+
boolean: true,
|
77
|
+
default: false
|
78
|
+
|
79
|
+
option :warning,
|
80
|
+
description: 'Warning threshold expression',
|
81
|
+
short: '-w WARNING',
|
82
|
+
long: '--warning WARNING',
|
83
|
+
default: nil
|
84
|
+
|
85
|
+
option :critical,
|
86
|
+
description: 'Critical threshold expression',
|
87
|
+
short: '-c CRITICAL',
|
88
|
+
long: '--critical CRITICAL',
|
89
|
+
default: nil
|
90
|
+
|
91
|
+
def run
|
92
|
+
begin
|
93
|
+
con = PG::Connection.new(config[:hostname], config[:port], nil, nil, config[:db], config[:user], config[:password])
|
94
|
+
res = con.exec("#{config[:query]}")
|
95
|
+
rescue PG::Error => e
|
96
|
+
unknown "Unable to query PostgreSQL: #{e.message}"
|
97
|
+
end
|
98
|
+
|
99
|
+
if config[:check_tuples]
|
100
|
+
value = res.ntuples
|
101
|
+
else
|
102
|
+
value = res.first.values.first.to_f
|
103
|
+
end
|
104
|
+
|
105
|
+
calc = Dentaku::Calculator.new
|
106
|
+
if config[:critical] && calc.evaluate(config[:critical], value: value)
|
107
|
+
critical "Results: #{res.values}"
|
108
|
+
elsif config[:warning] && calc.evaluate(config[:warning], value: value)
|
109
|
+
warning "Results: #{res.values}"
|
110
|
+
else
|
111
|
+
ok 'Query OK'
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -1,4 +1,30 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-postgres-replication
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
#
|
7
|
+
# This plugin checks postgresql replication lag
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# plain text
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: pg
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./check-postgres-replication.rb -m master_host -s slave_host -d db -u db_user -p db_pass -w warn_threshold -c crit_threshold
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
26
|
+
# for details.
|
27
|
+
#
|
2
28
|
|
3
29
|
require 'sensu-plugin/check/cli'
|
4
30
|
require 'pg'
|
@@ -1,18 +1,32 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
2
|
#
|
3
|
-
#
|
4
|
-
# ===
|
3
|
+
# metric-postgres-connections
|
5
4
|
#
|
6
|
-
#
|
7
|
-
# -----------
|
8
|
-
# - Ruby gem `pg`
|
5
|
+
# DESCRIPTION:
|
9
6
|
#
|
7
|
+
# This plugin collects postgres connection metrics
|
10
8
|
#
|
11
|
-
#
|
12
|
-
#
|
9
|
+
# OUTPUT:
|
10
|
+
# metric data
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: pg
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./metric-postgres-connections.rb -u db_user -p db_pass -h db_host -d db
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Copyright (c) 2012 Kwarter, Inc <platforms@kwarter.com>
|
26
|
+
# Author Gilles Devaux <gilles.devaux@gmail.com>
|
27
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
28
|
+
# for details.
|
13
29
|
#
|
14
|
-
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
15
|
-
# for details.
|
16
30
|
|
17
31
|
require 'sensu-plugin/metric/cli'
|
18
32
|
require 'pg'
|
@@ -1,18 +1,32 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
2
|
#
|
3
|
-
#
|
4
|
-
# ===
|
3
|
+
# metric-postgres-dbsize
|
5
4
|
#
|
6
|
-
#
|
7
|
-
# -----------
|
8
|
-
# - Ruby gem `pg`
|
5
|
+
# DESCRIPTION:
|
9
6
|
#
|
7
|
+
# This plugin collects postgres database size metrics
|
10
8
|
#
|
11
|
-
#
|
12
|
-
#
|
9
|
+
# OUTPUT:
|
10
|
+
# metric data
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: pg
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./metric-postgres-dbsize.rb -u db_user -p db_pass -h db_host -d db
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Copyright (c) 2012 Kwarter, Inc <platforms@kwarter.com>
|
26
|
+
# Author Gilles Devaux <gilles.devaux@gmail.com>
|
27
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
28
|
+
# for details.
|
13
29
|
#
|
14
|
-
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
15
|
-
# for details.
|
16
30
|
|
17
31
|
require 'sensu-plugin/metric/cli'
|
18
32
|
require 'pg'
|
@@ -1,4 +1,30 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# metric-postgres-graphite
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
#
|
7
|
+
# This plugin collects postgres replication lag metrics
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# metric data
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: pg
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./metric-postgres-graphite.rb -m master_host -s slave_host -d db -u db_user -p db_pass
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
26
|
+
# for details.
|
27
|
+
#
|
2
28
|
|
3
29
|
require 'pg'
|
4
30
|
require 'sensu-plugin/metric/cli'
|
@@ -1,18 +1,32 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
2
|
#
|
3
|
-
#
|
4
|
-
# ===
|
3
|
+
# metric-postgres-locks
|
5
4
|
#
|
6
|
-
#
|
7
|
-
# -----------
|
8
|
-
# - Ruby gem `pg`
|
5
|
+
# DESCRIPTION:
|
9
6
|
#
|
7
|
+
# This plugin collects postgres database lock metrics
|
10
8
|
#
|
11
|
-
#
|
12
|
-
#
|
9
|
+
# OUTPUT:
|
10
|
+
# metric data
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: pg
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./metric-postgres-locks.rb -u db_user -p db_pass -h db_host -d db
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Copyright (c) 2012 Kwarter, Inc <platforms@kwarter.com>
|
26
|
+
# Author Gilles Devaux <gilles.devaux@gmail.com>
|
27
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
28
|
+
# for details.
|
13
29
|
#
|
14
|
-
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
15
|
-
# for details.
|
16
30
|
|
17
31
|
require 'sensu-plugin/metric/cli'
|
18
32
|
require 'pg'
|
@@ -1,18 +1,32 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
2
|
#
|
3
|
-
#
|
4
|
-
# ===
|
3
|
+
# metric-postgres-statsbgwriter
|
5
4
|
#
|
6
|
-
#
|
7
|
-
# -----------
|
8
|
-
# - Ruby gem `pg`
|
5
|
+
# DESCRIPTION:
|
9
6
|
#
|
7
|
+
# This plugin collects postgres database bgwriter metrics
|
10
8
|
#
|
11
|
-
#
|
12
|
-
#
|
9
|
+
# OUTPUT:
|
10
|
+
# metric data
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: pg
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./metric-postgres-statsbgwriter.rb -u db_user -p db_pass -h db_host -d db
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Copyright (c) 2012 Kwarter, Inc <platforms@kwarter.com>
|
26
|
+
# Author Gilles Devaux <gilles.devaux@gmail.com>
|
27
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
28
|
+
# for details.
|
13
29
|
#
|
14
|
-
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
15
|
-
# for details.
|
16
30
|
|
17
31
|
require 'sensu-plugin/metric/cli'
|
18
32
|
require 'pg'
|
@@ -1,19 +1,33 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
2
|
#
|
3
|
-
#
|
4
|
-
# ===
|
3
|
+
# metric-postgres-statsdb
|
5
4
|
#
|
6
|
-
#
|
7
|
-
# -----------
|
8
|
-
# - PSQL `track_counts` `track_io_timing` for some metrics enabled
|
9
|
-
# - Ruby gem `pg`
|
5
|
+
# DESCRIPTION:
|
10
6
|
#
|
7
|
+
# This plugin collects postgres database metrics from the pg_stat_database table
|
11
8
|
#
|
12
|
-
#
|
13
|
-
#
|
9
|
+
# OUTPUT:
|
10
|
+
# metric data
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: pg
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./metric-postgres-statsdb.rb -u db_user -p db_pass -h db_host -d db
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
# Requires PSQL `track_counts` `track_io_timing` for some metrics enabled
|
24
|
+
#
|
25
|
+
# LICENSE:
|
26
|
+
# Copyright (c) 2012 Kwarter, Inc <platforms@kwarter.com>
|
27
|
+
# Author Gilles Devaux <gilles.devaux@gmail.com>
|
28
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
29
|
+
# for details.
|
14
30
|
#
|
15
|
-
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
16
|
-
# for details.
|
17
31
|
|
18
32
|
require 'sensu-plugin/metric/cli'
|
19
33
|
require 'pg'
|
@@ -1,19 +1,33 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
2
|
#
|
3
|
-
#
|
4
|
-
# ===
|
3
|
+
# metric-postgres-statsio
|
5
4
|
#
|
6
|
-
#
|
7
|
-
# -----------
|
8
|
-
# - PSQL `track_io_timing` enabled
|
9
|
-
# - Ruby gem `pg`
|
5
|
+
# DESCRIPTION:
|
10
6
|
#
|
7
|
+
# This plugin collects postgres database IO metrics
|
11
8
|
#
|
12
|
-
#
|
13
|
-
#
|
9
|
+
# OUTPUT:
|
10
|
+
# metric data
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: pg
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./metric-postgres-statsio.rb -u db_user -p db_pass -h db_host -d db -s scope
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
# Requires PSQL `track_io_timing` enabled
|
24
|
+
#
|
25
|
+
# LICENSE:
|
26
|
+
# Copyright (c) 2012 Kwarter, Inc <platforms@kwarter.com>
|
27
|
+
# Author Gilles Devaux <gilles.devaux@gmail.com>
|
28
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
29
|
+
# for details.
|
14
30
|
#
|
15
|
-
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
16
|
-
# for details.
|
17
31
|
|
18
32
|
require 'sensu-plugin/metric/cli'
|
19
33
|
require 'pg'
|
@@ -1,19 +1,33 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
2
|
#
|
3
|
-
#
|
4
|
-
# ===
|
3
|
+
# metric-postgres-statstable
|
5
4
|
#
|
6
|
-
#
|
7
|
-
# -----------
|
8
|
-
# - PSQL `track_counts` enabled
|
9
|
-
# - Ruby gem `pg`
|
5
|
+
# DESCRIPTION:
|
10
6
|
#
|
7
|
+
# This plugin collects postgres database metrics from the pg_stat tables
|
11
8
|
#
|
12
|
-
#
|
13
|
-
#
|
9
|
+
# OUTPUT:
|
10
|
+
# metric data
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: pg
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./metric-postgres-statstable.rb -u db_user -p db_pass -h db_host -d db -s scope
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
# Requires PSQL `track_counts` enabled
|
24
|
+
#
|
25
|
+
# LICENSE:
|
26
|
+
# Copyright (c) 2012 Kwarter, Inc <platforms@kwarter.com>
|
27
|
+
# Author Gilles Devaux <gilles.devaux@gmail.com>
|
28
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
29
|
+
# for details.
|
14
30
|
#
|
15
|
-
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
16
|
-
# for details.
|
17
31
|
|
18
32
|
require 'sensu-plugin/metric/cli'
|
19
33
|
require 'pg'
|
@@ -0,0 +1,98 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# metrics-postgres-query
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin collects metrics from the results of a postgres query. Can optionally
|
7
|
+
# count the number of tuples (rows) returned by the query.
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# metric data
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: pg
|
17
|
+
# gem: sensu-plugin
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# metrics-postgres-query.rb -u db_user -p db_pass -h db_server -d db -q 'select foo from bar'
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Copyright 2015, Eric Heydrick <eheydrick@gmail.com>
|
26
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
27
|
+
# for details.
|
28
|
+
#
|
29
|
+
|
30
|
+
require 'sensu-plugin/metric/cli'
|
31
|
+
require 'pg'
|
32
|
+
|
33
|
+
class MetricsPostgresQuery < Sensu::Plugin::Metric::CLI::Graphite
|
34
|
+
option :user,
|
35
|
+
description: 'Postgres User',
|
36
|
+
short: '-u USER',
|
37
|
+
long: '--user USER'
|
38
|
+
|
39
|
+
option :password,
|
40
|
+
description: 'Postgres Password',
|
41
|
+
short: '-p PASS',
|
42
|
+
long: '--password PASS'
|
43
|
+
|
44
|
+
option :hostname,
|
45
|
+
description: 'Hostname to login to',
|
46
|
+
short: '-h HOST',
|
47
|
+
long: '--hostname HOST',
|
48
|
+
default: 'localhost'
|
49
|
+
|
50
|
+
option :port,
|
51
|
+
description: 'Database port',
|
52
|
+
short: '-P PORT',
|
53
|
+
long: '--port PORT',
|
54
|
+
default: 5432
|
55
|
+
|
56
|
+
option :db,
|
57
|
+
description: 'Database name',
|
58
|
+
short: '-d DB',
|
59
|
+
long: '--db DB',
|
60
|
+
default: 'postgres'
|
61
|
+
|
62
|
+
option :query,
|
63
|
+
description: 'Database query to execute',
|
64
|
+
short: '-q QUERY',
|
65
|
+
long: '--query QUERY',
|
66
|
+
required: true
|
67
|
+
|
68
|
+
option :count_tuples,
|
69
|
+
description: 'Count the number of tuples (rows) returned by the query',
|
70
|
+
short: '-t',
|
71
|
+
long: '--tuples',
|
72
|
+
boolean: true,
|
73
|
+
default: false
|
74
|
+
|
75
|
+
option :scheme,
|
76
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
77
|
+
short: '-s SCHEME',
|
78
|
+
long: '--scheme SCHEME',
|
79
|
+
default: 'postgres'
|
80
|
+
|
81
|
+
def run
|
82
|
+
begin
|
83
|
+
con = PG::Connection.new(config[:hostname], config[:port], nil, nil, config[:db], config[:user], config[:password])
|
84
|
+
res = con.exec("#{config[:query]}")
|
85
|
+
rescue PG::Error => e
|
86
|
+
unknown "Unable to query PostgreSQL: #{e.message}"
|
87
|
+
end
|
88
|
+
|
89
|
+
if config[:check_tuples]
|
90
|
+
value = res.ntuples
|
91
|
+
else
|
92
|
+
value = res.first.values.first
|
93
|
+
end
|
94
|
+
|
95
|
+
output config[:scheme], value
|
96
|
+
ok
|
97
|
+
end
|
98
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-postgres
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
|
31
31
|
HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2015-10-
|
33
|
+
date: 2015-10-08 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: sensu-plugin
|
@@ -60,6 +60,20 @@ dependencies:
|
|
60
60
|
- - '='
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: 0.18.3
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: dentaku
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.0.4
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 2.0.4
|
63
77
|
- !ruby/object:Gem::Dependency
|
64
78
|
name: bundler
|
65
79
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,14 +178,14 @@ dependencies:
|
|
164
178
|
requirements:
|
165
179
|
- - '='
|
166
180
|
- !ruby/object:Gem::Version
|
167
|
-
version: 0.
|
181
|
+
version: 0.34.2
|
168
182
|
type: :development
|
169
183
|
prerelease: false
|
170
184
|
version_requirements: !ruby/object:Gem::Requirement
|
171
185
|
requirements:
|
172
186
|
- - '='
|
173
187
|
- !ruby/object:Gem::Version
|
174
|
-
version: 0.
|
188
|
+
version: 0.34.2
|
175
189
|
- !ruby/object:Gem::Dependency
|
176
190
|
name: yard
|
177
191
|
requirement: !ruby/object:Gem::Requirement
|
@@ -195,6 +209,7 @@ description: |-
|
|
195
209
|
more.
|
196
210
|
email: "<sensu-users@googlegroups.com>"
|
197
211
|
executables:
|
212
|
+
- metrics-postgres-query.rb
|
198
213
|
- metric-postgres-statstable.rb
|
199
214
|
- metric-postgres-statsio.rb
|
200
215
|
- metric-postgres-statsdb.rb
|
@@ -204,6 +219,7 @@ executables:
|
|
204
219
|
- metric-postgres-dbsize.rb
|
205
220
|
- metric-postgres-connections.rb
|
206
221
|
- check-postgres-replication.rb
|
222
|
+
- check-postgres-query.rb
|
207
223
|
- check-postgres-alive.rb
|
208
224
|
extensions: []
|
209
225
|
extra_rdoc_files: []
|
@@ -212,6 +228,7 @@ files:
|
|
212
228
|
- LICENSE
|
213
229
|
- README.md
|
214
230
|
- bin/check-postgres-alive.rb
|
231
|
+
- bin/check-postgres-query.rb
|
215
232
|
- bin/check-postgres-replication.rb
|
216
233
|
- bin/metric-postgres-connections.rb
|
217
234
|
- bin/metric-postgres-dbsize.rb
|
@@ -221,6 +238,7 @@ files:
|
|
221
238
|
- bin/metric-postgres-statsdb.rb
|
222
239
|
- bin/metric-postgres-statsio.rb
|
223
240
|
- bin/metric-postgres-statstable.rb
|
241
|
+
- bin/metrics-postgres-query.rb
|
224
242
|
- lib/sensu-plugins-postgres.rb
|
225
243
|
- lib/sensu-plugins-postgres/version.rb
|
226
244
|
homepage: https://github.com/sensu-plugins/sensu-plugins-postgres
|
metadata.gz.sig
CHANGED
Binary file
|