riemann-babbler 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b12b09f0206a5293f373dcfb2fc94d0451c446bd
4
- data.tar.gz: 24c516afe7a4fd13b66d9b60c089e77d8d9a15f6
3
+ metadata.gz: 9915b5a001d3c3f81b76a15e7c50c848c94f59e6
4
+ data.tar.gz: 21db07879c0c11ee089a0597f7976404c45c26fe
5
5
  SHA512:
6
- metadata.gz: 6eee0b673ca94e64051c5ace8088b686fc79d4762fa35a6283ec0fc0e7097f25c1af4c924028c793ea42cc870539d19307608280ab8c433f7702e9f79bdcbf85
7
- data.tar.gz: 46414b6df6a30f163816ccf21134ee8fb3c12f570eac191ec0650841cd0202159e58ccd758cecf0e36be556da75ad687973dd9eabc70657ffa8f3a9fc396f7b8
6
+ metadata.gz: 74c7ed6b265d2a7d366b26fab1e6df92d21d4b29fc60fa5e6652451ff8ef201a09f6b8f2562624e5246073ebc6338299249b7c4147bf5bc8b6dc9f2910db4147
7
+ data.tar.gz: a4c58781c080e2777668b4e84f6915bc069599761c8c3b06aa60f5511efe9b66c49db027349e1fa6f3494a6235068977e2f5e1860a6ac5eaf293dcfa993a10ee
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- riemann-babbler (2.0.4)
4
+ riemann-babbler (2.0.5)
5
5
  configatron
6
6
  docile
7
7
  file-tail
@@ -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(:chk_file, '/usr/bin/pg_config')
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.chk_file
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}\" postgres")
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
- status << rep_lag_state if in_recovery?
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
@@ -1,5 +1,5 @@
1
1
  module Riemann
2
2
  module Babbler
3
- VERSION = '2.0.4'
3
+ VERSION = '2.0.5'
4
4
  end
5
5
  end
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
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-06 00:00:00.000000000 Z
11
+ date: 2013-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: riemann-client