riemann-babbler 1.2.7 → 1.2.8

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.
@@ -14,8 +14,17 @@ class Riemann::Babbler::Mdadm < Riemann::Babbler
14
14
  file = File.read('/proc/mdstat').split("\n")
15
15
  status = Array.new
16
16
  file.each_with_index do |line, index|
17
- next unless line.include? '_'
17
+ next unless line.include?('blocks')
18
+
18
19
  device = file[index-1].split(':')[0].strip
20
+
21
+ mdstatus = line.split(" ").last
22
+ next if mdstatus == '[UU]' # пропускаем все збс
23
+ if mdstatus == plugin.states.send(device).to_s # пропускаем если стейт зафикисирован в конфиге
24
+ status << { :service => plugin.service + " #{device}", :metric => 1, :state => 'ok', :description => "mdadm failed device #{device}, but disabled in config" }
25
+ next
26
+ end
27
+
19
28
  status << { :service => plugin.service + " #{device}", :metric => 1, :description => "mdadm failed device #{device}: #{get_failed_parts(device)}" }
20
29
  end
21
30
  status
@@ -0,0 +1,70 @@
1
+ class Riemann::Babbler::Pgsql < Riemann::Babbler
2
+
3
+ def init
4
+ plugin.set_default(:service, 'pgsql')
5
+ plugin.set_default(:host, '127.0.0.1')
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
+
13
+ plugin.set_default(:conn_warn, 5)
14
+ plugin.set_default(:conn_crit, 3)
15
+
16
+ plugin.set_default(:interval, 60)
17
+ end
18
+
19
+ def run_plugin
20
+ File.exists? plugin.chk_file
21
+ end
22
+
23
+ def run_sql(sql)
24
+ shell("psql -h #{plugin.host} -U #{plugin.user} -tnc \"#{sql}\" postgres")
25
+ end
26
+
27
+ def in_recovery?
28
+ run_sql('select pg_is_in_recovery()') == 't'
29
+ end
30
+
31
+ # connection to pg
32
+ def connections
33
+ max_conn = run_sql("show max_connections").to_i
34
+ res_conn = run_sql("show superuser_reserved_connections").to_i
35
+ cur_conn = run_sql("select count(1) from pg_stat_activity;").to_i
36
+ [cur_conn, (max_conn - res_conn - cur_conn)]
37
+ end
38
+
39
+ def rep_lag_state
40
+ rep_lag = run_sql(plugin.rep_lag_sql).to_i
41
+ if rep_lag >= plugin.rep_lag_crit || rep_lag == 0
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
+ def collect
51
+ status = Array.new
52
+
53
+ cur_conn, res_conn = connections
54
+
55
+ status << rep_lag_state if in_recovery?
56
+ status << { :service => plugin.service + ' connections', :description => "Postgresql current connections", :state => 'ok', :metric => cur_conn }
57
+
58
+ # check reserved pool size
59
+ if res_conn < plugin.conn_warn
60
+ if res_conn > plugin.conn_crit
61
+ status << { :service => plugin.service + ' reserved connections', :description => "Postgresql reserved connections state", :state => 'warning', :metric => res_conn }
62
+ else
63
+ status << { :service => plugin.service + ' reserved connections', :description => "Postgresql reserved connections state", :state => 'critical', :metric => res_conn }
64
+ end
65
+ end
66
+
67
+ status
68
+ end
69
+
70
+ end
@@ -1,5 +1,5 @@
1
1
  module Riemann
2
2
  class Babbler
3
- VERSION = '1.2.7'
3
+ VERSION = '1.2.8'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riemann-babbler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.2.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-20 00:00:00.000000000 Z
12
+ date: 2013-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: riemann-client
@@ -204,6 +204,7 @@ files:
204
204
  - lib/riemann/babbler/plugins/net.rb
205
205
  - lib/riemann/babbler/plugins/net_stat.rb
206
206
  - lib/riemann/babbler/plugins/nginx.rb
207
+ - lib/riemann/babbler/plugins/pgsql.rb
207
208
  - lib/riemann/babbler/plugins/runit.rb
208
209
  - lib/riemann/babbler/plugins/status_file.rb
209
210
  - lib/riemann/babbler/plugins/tw_cli.rb