riemann-babbler 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/riemann/babbler/plugins/pgsql.rb +30 -22
- data/lib/riemann/babbler/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9915b5a001d3c3f81b76a15e7c50c848c94f59e6
|
4
|
+
data.tar.gz: 21db07879c0c11ee089a0597f7976404c45c26fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74c7ed6b265d2a7d366b26fab1e6df92d21d4b29fc60fa5e6652451ff8ef201a09f6b8f2562624e5246073ebc6338299249b7c4147bf5bc8b6dc9f2910db4147
|
7
|
+
data.tar.gz: a4c58781c080e2777668b4e84f6915bc069599761c8c3b06aa60f5511efe9b66c49db027349e1fa6f3494a6235068977e2f5e1860a6ac5eaf293dcfa993a10ee
|
data/Gemfile.lock
CHANGED
@@ -4,30 +4,44 @@ class Riemann::Babbler::Plugin::Pgsql < Riemann::Babbler::Plugin
|
|
4
4
|
plugin.set_default(:service, 'pgsql')
|
5
5
|
plugin.set_default(:host, '127.0.0.1')
|
6
6
|
plugin.set_default(:user, 'postgres')
|
7
|
-
plugin.set_default(:
|
8
|
-
|
9
|
-
plugin.set_default(:rep_lag_sql, "select date_part('epoch', pg_last_xact_replay_timestamp() - now())::int")
|
10
|
-
plugin.set_default(:rep_lag_warn, 500)
|
11
|
-
plugin.set_default(:rep_lag_crit, 1000)
|
12
|
-
|
7
|
+
plugin.set_default(:psql, '/usr/bin/psql')
|
8
|
+
plugin.set_default(:db4monit, 'riemann_monit')
|
13
9
|
plugin.set_default(:conn_warn, 5)
|
14
10
|
plugin.set_default(:conn_crit, 3)
|
15
|
-
|
11
|
+
plugin.states.set_default(:warning, 120) # repl lag
|
12
|
+
plugin.states.set_default(:critical, 500) # repl lag
|
16
13
|
plugin.set_default(:interval, 60)
|
17
14
|
end
|
18
15
|
|
19
16
|
def run_plugin
|
20
|
-
File.exists? plugin.
|
17
|
+
File.exists? plugin.psql
|
21
18
|
end
|
22
19
|
|
23
|
-
def run_sql(sql)
|
24
|
-
shell("psql -h #{plugin.host} -U #{plugin.user} -tnc \"#{sql}\"
|
20
|
+
def run_sql(sql, db='postgres')
|
21
|
+
shell("#{plugin.psql} -h #{plugin.host} -U #{plugin.user} -tnc \"#{sql}\" #{db}")
|
25
22
|
end
|
26
23
|
|
27
24
|
def in_recovery?
|
28
25
|
run_sql('select pg_is_in_recovery()') == 't'
|
29
26
|
end
|
30
27
|
|
28
|
+
def db_exists?
|
29
|
+
run_sql("select 1 from pg_database where datname = '#{plugin.db4monit}'") == '1'
|
30
|
+
end
|
31
|
+
|
32
|
+
def run_master_sql
|
33
|
+
run_sql("create database #{plugin.db4monit}") unless db_exists?
|
34
|
+
run_sql(
|
35
|
+
"drop table if exists timestamp; \
|
36
|
+
create table timestamp ( id int primary key, value timestamp default now() ); \
|
37
|
+
insert into timestamp (id) values (1); \
|
38
|
+
", plugin.db4monit)
|
39
|
+
end
|
40
|
+
|
41
|
+
def repl_lag
|
42
|
+
unixnow - run_sql("select extract(epoch from value::timestamp) from timestamp where id = 1;", plugin.db4monit).to_i
|
43
|
+
end
|
44
|
+
|
31
45
|
# connection to pg
|
32
46
|
def connections
|
33
47
|
max_conn = run_sql('show max_connections').to_i
|
@@ -36,23 +50,17 @@ class Riemann::Babbler::Plugin::Pgsql < Riemann::Babbler::Plugin
|
|
36
50
|
[cur_conn, (max_conn - res_conn - cur_conn)]
|
37
51
|
end
|
38
52
|
|
39
|
-
def rep_lag_state
|
40
|
-
rep_lag = run_sql(plugin.rep_lag_sql).to_i.abs
|
41
|
-
if rep_lag >= plugin.rep_lag_crit
|
42
|
-
{ :service => plugin.service + ' rep_lag', :description => 'Postgresql replication lag state', :state => 'critical', :metric => rep_lag }
|
43
|
-
elsif rep_lag >= plugin.rep_lag_warn
|
44
|
-
{ :service => plugin.service + ' rep_lag', :description => 'Postgresql replication lag state', :state => 'warning', :metric => rep_lag }
|
45
|
-
else
|
46
|
-
{ :service => plugin.service + ' rep_lag', :description => 'Postgresql replication lag state', :state => 'ok', :metric => rep_lag }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
53
|
def collect
|
51
54
|
status = Array.new
|
52
55
|
|
53
56
|
cur_conn, res_conn = connections
|
54
57
|
|
55
|
-
|
58
|
+
if in_recovery?
|
59
|
+
status << { :service => plugin.service + ' replication lag', :description => 'Postgresql replication lag', :metric => repl_lag }
|
60
|
+
else
|
61
|
+
run_master_sql
|
62
|
+
end
|
63
|
+
|
56
64
|
status << { :service => plugin.service + ' connections', :description => 'Postgresql current connections', :state => 'ok', :metric => cur_conn }
|
57
65
|
|
58
66
|
# check reserved pool size
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riemann-babbler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vasiliev Dmitry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: riemann-client
|