Skip to content

Commit 7b079f4

Browse files
committed
fix: #179 added WAL filename check before gathering Archive Queue Size and Archive Queue Length
1 parent ff70db6 commit 7b079f4

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

mamonsu/plugins/pgsql/archive_command.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from distutils.version import LooseVersion
33
from .pool import Pooler
44
from mamonsu.lib.zbx_template import ZbxTemplate
5+
import re
56

67

78
class ArchiveCommand(Plugin):
@@ -77,32 +78,35 @@ def run(self, zbx):
7778
"""
7879

7980
self.disable_and_exit_if_archive_mode_is_not_on()
81+
8082
if Pooler.is_bootstraped() and Pooler.bootstrap_version_greater('2.3.4'):
81-
result2 = Pooler.query("""SELECT * from mamonsu.archive_stat()""")
82-
result1 = Pooler.query("""select * from mamonsu.archive_command_files()""")
83+
result_stats = Pooler.query("""SELECT * from mamonsu.archive_stat()""")
8384
else:
84-
if Pooler.server_version_greater('10.0'):
85-
result1 = Pooler.query(query_queue.format('wal_lsn', 'walfile'))
86-
else:
87-
result1 = Pooler.query(query_queue.format('xlog_location', 'xlogfile'))
88-
result2 = Pooler.query("""SELECT archived_count, failed_count from pg_stat_archiver;""")
89-
90-
current_archived_count = result2[0][0]
91-
current_failed_count = result2[0][1]
92-
85+
result_stats = Pooler.query("""SELECT archived_count, failed_count from pg_stat_archiver;""")
86+
current_archived_count = result_stats[0][0]
87+
current_failed_count = result_stats[0][1]
9388
if self.old_archived_count is not None:
9489
archived_count = current_archived_count - self.old_archived_count
9590
zbx.send('pgsql.archive_command[{0}]'.format(self.Items[2][0]), archived_count)
96-
9791
if self.old_failed_count is not None:
9892
failed_count = current_failed_count - self.old_failed_count
9993
zbx.send('pgsql.archive_command[{0}]'.format(self.Items[3][0]), failed_count)
100-
10194
self.old_archived_count = current_archived_count
10295
self.old_failed_count = current_failed_count
10396

104-
zbx.send('pgsql.archive_command[{0}]'.format(self.Items[0][0]), result1[0][0])
105-
zbx.send('pgsql.archive_command[{0}]'.format(self.Items[1][0]), result1[0][1])
97+
# check the last WAL file name to avoid XXX.history, XXX.partial, etc.
98+
wal_exists = bool(re.search('^[0-9A-Z]{24}$', str(
99+
Pooler.query("""SELECT pg_stat_archiver.last_archived_wal FROM pg_stat_archiver;""")[0][0])))
100+
if wal_exists:
101+
if Pooler.is_bootstraped() and Pooler.bootstrap_version_greater('2.3.4'):
102+
result_queue = Pooler.query("""select * from mamonsu.archive_command_files()""")
103+
else:
104+
if Pooler.server_version_greater('10.0'):
105+
result_queue = Pooler.query(query_queue.format('wal_lsn', 'walfile'))
106+
else:
107+
result_queue = Pooler.query(query_queue.format('xlog_location', 'xlogfile'))
108+
zbx.send('pgsql.archive_command[{0}]'.format(self.Items[0][0]), result_queue[0][0])
109+
zbx.send('pgsql.archive_command[{0}]'.format(self.Items[1][0]), result_queue[0][1])
106110

107111
def items(self, template, dashboard=False):
108112
result = ''

0 commit comments

Comments
 (0)