check_slony 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/check_slony +88 -0
- data/lib/check_slony.rb +1 -88
- metadata +3 -3
data/bin/check_slony
CHANGED
@@ -1,3 +1,91 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
requrie 'rubygems'
|
4
|
+
require 'pg'
|
5
|
+
require 'optparse'
|
6
|
+
require 'timeout'
|
7
|
+
|
8
|
+
|
9
|
+
pgoptions=''
|
10
|
+
pgtty=''
|
11
|
+
@result=''
|
12
|
+
@problems = 0
|
13
|
+
@timeout = 10
|
14
|
+
|
15
|
+
OptionParser.new do |opt|
|
16
|
+
opt.on("-H","--host=DBHOSTNAME", String, "Specify the DBHOSTNAME"){|h| @hostname = h }
|
17
|
+
opt.on("-P","--port=PORTNUMBER", Integer, "Specify the DB port number"){|p| @port = p }
|
18
|
+
opt.on("-u","--username=DBUSER", String, "Specify the DB user name"){|u| @user = u }
|
19
|
+
opt.on("-d","--dbname=DBNAME", String, "Specify the DB name"){|d| @dbname = d }
|
20
|
+
opt.on("-p","--password=PASSWORD", String, "Specify the DB password"){|p| @password = p }
|
21
|
+
opt.on("-C","--cluster=CLUSTERNAME", String, "Specify the DB CLUSTER NAME"){|c| @cluster = c }
|
22
|
+
opt.on("-e","--events=EVENTS", Integer, "Specify the Event Counts"){|e| @event = e }
|
23
|
+
opt.on("-l","--lagtime=LAGTIME", Integer, "Specify the LAGTIME"){|l| @lagtime = l }
|
24
|
+
opt.on("-t","--timeout=TIMEOUT", Integer, "Specify the TIMEOUT"){|t| @timeout = t }
|
25
|
+
|
26
|
+
begin
|
27
|
+
opt.parse!(ARGV)
|
28
|
+
rescue OptionParser::ParseError => err
|
29
|
+
$stderr.puts err.message
|
30
|
+
$stderr.puts opt.help
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
timeout(@timeout){
|
36
|
+
# sleep 3 # for debug
|
37
|
+
con = PGconn.new(@hostname, @port, pgoptions, pgtty, @dbname, @user, @password)
|
38
|
+
query = 'SELECT st_origin, st_received, st_lag_num_events, round(extract(epoch from st_lag_time)) from "_' + @cluster + '".sl_status'
|
39
|
+
|
40
|
+
res = con.exec(query)
|
41
|
+
unless res
|
42
|
+
print "POSTGRES_REPLICATION_LAG CRITICAL: Cannot prepare $DBI::errstr\n";
|
43
|
+
exit 2
|
44
|
+
end
|
45
|
+
|
46
|
+
res.each do |r|
|
47
|
+
|
48
|
+
node = r["st_received"]
|
49
|
+
master = r["st_origin"]
|
50
|
+
lag = r["st_lag_num_events"]
|
51
|
+
round = r["round"]
|
52
|
+
|
53
|
+
@result += "SUBSCRIBER " + node + " ON ORIGIN " + master + " : EVENT LAG=" + lag
|
54
|
+
if (lag.to_i > 0) && (@event < lag.to_i)
|
55
|
+
@result = @result + " (BEHIND " + (lag.to_i - @event).to_s + ") ";
|
56
|
+
@problems += 1
|
57
|
+
end
|
58
|
+
@result = @result + " TIME LAG=" + round + "s";
|
59
|
+
|
60
|
+
if (@lagtime > 0) && (@lagtime < round.to_i)
|
61
|
+
@result = @result + " (BEHIND " + (round.to_i - @lagtime).to_s + "s) ";
|
62
|
+
@problems += 1
|
63
|
+
end
|
64
|
+
@result = @result + " || ";
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
if @problems > 0
|
69
|
+
@result = "POSTGRES_REPLICATION_LAG CRITICAL: " + @result + "\n"
|
70
|
+
print @result
|
71
|
+
exit 2
|
72
|
+
else
|
73
|
+
@result = "POSTGRES_REPLICATION_LAG OK: " + @result + "\n"
|
74
|
+
print @result
|
75
|
+
exit 0
|
76
|
+
end
|
77
|
+
|
78
|
+
print $problems;
|
79
|
+
con.close
|
80
|
+
}
|
81
|
+
|
82
|
+
rescue Timeout::Error => ex
|
83
|
+
print "POSTGRES_REPLICATION_LAG TIMEOUT: #{ex.message}";
|
84
|
+
exit 3
|
85
|
+
rescue => ex
|
86
|
+
print "POSTGRES_REPLICATION_LAG UNKNOWN: #{ex.message}";
|
87
|
+
exit 3
|
88
|
+
end
|
89
|
+
|
90
|
+
exit;
|
3
91
|
abort "you need to write me"
|
data/lib/check_slony.rb
CHANGED
@@ -1,91 +1,4 @@
|
|
1
|
-
requrie 'rubygems'
|
2
|
-
require 'pg'
|
3
|
-
require 'optparse'
|
4
|
-
require 'timeout'
|
5
|
-
|
6
1
|
class CheckSlony
|
7
|
-
VERSION = '0.0.
|
8
|
-
end
|
9
|
-
|
10
|
-
pgoptions=''
|
11
|
-
pgtty=''
|
12
|
-
@result=''
|
13
|
-
@problems = 0
|
14
|
-
@timeout = 10
|
15
|
-
|
16
|
-
OptionParser.new do |opt|
|
17
|
-
opt.on("-H","--host=DBHOSTNAME", String, "Specify the DBHOSTNAME"){|h| @hostname = h }
|
18
|
-
opt.on("-P","--port=PORTNUMBER", Integer, "Specify the DB port number"){|p| @port = p }
|
19
|
-
opt.on("-u","--username=DBUSER", String, "Specify the DB user name"){|u| @user = u }
|
20
|
-
opt.on("-d","--dbname=DBNAME", String, "Specify the DB name"){|d| @dbname = d }
|
21
|
-
opt.on("-p","--password=PASSWORD", String, "Specify the DB password"){|p| @password = p }
|
22
|
-
opt.on("-C","--cluster=CLUSTERNAME", String, "Specify the DB CLUSTER NAME"){|c| @cluster = c }
|
23
|
-
opt.on("-e","--events=EVENTS", Integer, "Specify the Event Counts"){|e| @event = e }
|
24
|
-
opt.on("-l","--lagtime=LAGTIME", Integer, "Specify the LAGTIME"){|l| @lagtime = l }
|
25
|
-
opt.on("-t","--timeout=TIMEOUT", Integer, "Specify the TIMEOUT"){|t| @timeout = t }
|
26
|
-
|
27
|
-
begin
|
28
|
-
opt.parse!(ARGV)
|
29
|
-
rescue OptionParser::ParseError => err
|
30
|
-
$stderr.puts err.message
|
31
|
-
$stderr.puts opt.help
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
begin
|
36
|
-
timeout(@timeout){
|
37
|
-
# sleep 3 # for debug
|
38
|
-
con = PGconn.new(@hostname, @port, pgoptions, pgtty, @dbname, @user, @password)
|
39
|
-
query = 'SELECT st_origin, st_received, st_lag_num_events, round(extract(epoch from st_lag_time)) from "_' + @cluster + '".sl_status'
|
40
|
-
|
41
|
-
res = con.exec(query)
|
42
|
-
unless res
|
43
|
-
print "POSTGRES_REPLICATION_LAG CRITICAL: Cannot prepare $DBI::errstr\n";
|
44
|
-
exit 2
|
45
|
-
end
|
46
|
-
|
47
|
-
res.each do |r|
|
48
|
-
|
49
|
-
node = r["st_received"]
|
50
|
-
master = r["st_origin"]
|
51
|
-
lag = r["st_lag_num_events"]
|
52
|
-
round = r["round"]
|
53
|
-
|
54
|
-
@result += "SUBSCRIBER " + node + " ON ORIGIN " + master + " : EVENT LAG=" + lag
|
55
|
-
if (lag.to_i > 0) && (@event < lag.to_i)
|
56
|
-
@result = @result + " (BEHIND " + (lag.to_i - @event).to_s + ") ";
|
57
|
-
@problems += 1
|
58
|
-
end
|
59
|
-
@result = @result + " TIME LAG=" + round + "s";
|
60
|
-
|
61
|
-
if (@lagtime > 0) && (@lagtime < round.to_i)
|
62
|
-
@result = @result + " (BEHIND " + (round.to_i - @lagtime).to_s + "s) ";
|
63
|
-
@problems += 1
|
64
|
-
end
|
65
|
-
@result = @result + " || ";
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
if @problems > 0
|
70
|
-
@result = "POSTGRES_REPLICATION_LAG CRITICAL: " + @result + "\n"
|
71
|
-
print @result
|
72
|
-
exit 2
|
73
|
-
else
|
74
|
-
@result = "POSTGRES_REPLICATION_LAG OK: " + @result + "\n"
|
75
|
-
print @result
|
76
|
-
exit 0
|
77
|
-
end
|
78
|
-
|
79
|
-
print $problems;
|
80
|
-
con.close
|
81
|
-
}
|
82
|
-
|
83
|
-
rescue Timeout::Error => ex
|
84
|
-
print "POSTGRES_REPLICATION_LAG TIMEOUT: #{ex.message}";
|
85
|
-
exit 3
|
86
|
-
rescue => ex
|
87
|
-
print "POSTGRES_REPLICATION_LAG UNKNOWN: #{ex.message}";
|
88
|
-
exit 3
|
2
|
+
VERSION = '0.0.2'
|
89
3
|
end
|
90
4
|
|
91
|
-
exit;
|
metadata
CHANGED