Skip to content

Commit 02004df

Browse files
committed
Merge branch 'dev'
2 parents 65f4837 + f83f325 commit 02004df

File tree

7 files changed

+46
-43
lines changed

7 files changed

+46
-43
lines changed

.github/workflows/mamonsu-tests-dev.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Mamonsu tests
1+
name: Mamonsu DEV
22

33
on:
44
push:
@@ -18,7 +18,7 @@ jobs:
1818
matrix:
1919
docker_os: ['centos:7']
2020
zabbix_version: ['5.4']
21-
pg_version: ['9.6', '10', '11', '12', '13']
21+
pg_version: ['9.6', '10', '11', '12', '13', '14']
2222

2323
steps:
2424
- name: Checkout Mamonsu repo

.github/workflows/mamonsu-tests-master.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Mamonsu tests
1+
name: Mamonsu MASTER
22

33
on:
44
push:
@@ -18,7 +18,7 @@ jobs:
1818
matrix:
1919
docker_os: ['ubuntu:20.04', 'centos:7', 'centos:8']
2020
zabbix_version: ['3.0', '4.0', '5.0', '5.4']
21-
pg_version: ['9.6', '10', '11', '12', '13']
21+
pg_version: ['9.6', '10', '11', '12', '13', '14']
2222

2323
steps:
2424
- name: Checkout Mamonsu repo

.travis.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

github-actions-tests/tools/bootstrap.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,7 @@ mamonsu bootstrap -x -U test_superuser -h localhost -p 5432
141141
# check
142142
check_db_objects mamonsu test_superuser
143143

144+
# bootstrap for other tests
145+
mamonsu bootstrap -x -U postgres -d mamonsu_test_db
146+
144147
exit 0

mamonsu/plugins/pgsql/archive_command.py

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from mamonsu.plugins.pgsql.plugin import PgsqlPlugin as Plugin
2+
from distutils.version import LooseVersion
23
from .pool import Pooler
34
from mamonsu.lib.zbx_template import ZbxTemplate
45

@@ -12,14 +13,14 @@ class ArchiveCommand(Plugin):
1213
query_agent_count_files = """
1314
WITH values AS (
1415
SELECT
15-
4096/(pg_settings.setting::bigint/1024/1024) AS segment_parts_count,
16+
4096/(coalesce(1, pg_settings.setting::bigint/1024/1024)) AS segment_parts_count,
1617
setting::bigint AS segment_size,
1718
('x' || substring(pg_stat_archiver.last_archived_wal from 9 for 8))::bit(32)::int AS last_wal_div,
1819
('x' || substring(pg_stat_archiver.last_archived_wal from 17 for 8))::bit(32)::int AS last_wal_mod,
1920
CASE WHEN pg_is_in_recovery() THEN NULL ELSE
20-
('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 9 for 8))::bit(32)::int END AS current_wal_div,
21+
('x' || substring(pg_{1}_name(pg_current_{0}()) from 9 for 8))::bit(32)::int END AS current_wal_div,
2122
CASE WHEN pg_is_in_recovery() THEN NULL ELSE
22-
('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 17 for 8))::bit(32)::int END AS current_wal_mod
23+
('x' || substring(pg_{1}_name(pg_current_{0}()) from 17 for 8))::bit(32)::int END AS current_wal_mod
2324
FROM pg_settings, pg_stat_archiver
2425
WHERE pg_settings.name = 'wal_segment_size')
2526
SELECT greatest(coalesce((segment_parts_count - last_wal_mod) + ((current_wal_div - last_wal_div - 1) * segment_parts_count) + current_wal_mod - 1, 0), 0) AS count_files
@@ -28,17 +29,17 @@ class ArchiveCommand(Plugin):
2829
query_agent_size_files = """
2930
WITH values AS (
3031
SELECT
31-
4096/(pg_settings.setting::bigint/1024/1024) AS segment_parts_count,
32+
4096/(coalesce(1, pg_settings.setting::bigint/1024/1024)) AS segment_parts_count,
3233
setting::bigint AS segment_size,
3334
('x' || substring(pg_stat_archiver.last_archived_wal from 9 for 8))::bit(32)::int AS last_wal_div,
3435
('x' || substring(pg_stat_archiver.last_archived_wal from 17 for 8))::bit(32)::int AS last_wal_mod,
3536
CASE WHEN pg_is_in_recovery() THEN NULL ELSE
36-
('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 9 for 8))::bit(32)::int END AS current_wal_div,
37+
('x' || substring(pg_{1}_name(pg_current_{0}()) from 9 for 8))::bit(32)::int END AS current_wal_div,
3738
CASE WHEN pg_is_in_recovery() THEN NULL ELSE
38-
('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 17 for 8))::bit(32)::int END AS current_wal_mod
39+
('x' || substring(pg_{1}_name(pg_current_{0}()) from 17 for 8))::bit(32)::int END AS current_wal_mod
3940
FROM pg_settings, pg_stat_archiver
4041
WHERE pg_settings.name = 'wal_segment_size')
41-
SELECT greatest(coalesce(((segment_parts_count - last_wal_mod) + ((current_wal_div - last_wal_div - 1) * segment_parts_count) + current_wal_mod - 1) * segment_size, 0), 0) AS size_files
42+
greatest(coalesce(((segment_parts_count - last_wal_mod) + ((current_wal_div - last_wal_div - 1) * segment_parts_count) + current_wal_mod - 1) * segment_size, 0), 0) AS size_files
4243
FROM values;
4344
"""
4445

@@ -57,28 +58,33 @@ class ArchiveCommand(Plugin):
5758
old_failed_count = None
5859

5960
def run(self, zbx):
60-
self.disable_and_exit_if_archive_mode_is_not_on()
61-
if Pooler.is_bootstraped() and Pooler.bootstrap_version_greater('2.3.4'):
62-
result2 = Pooler.query("""SELECT * from mamonsu.archive_stat()""")
63-
result1 = Pooler.query("""select * from mamonsu.archive_command_files()""")
64-
else:
65-
result1 = Pooler.query("""
61+
query_queue = """
6662
WITH values AS (
6763
SELECT
68-
4096/(pg_settings.setting::bigint/1024/1024) AS segment_parts_count,
64+
4096/(coalesce(1, pg_settings.setting::bigint/1024/1024)) AS segment_parts_count,
6965
setting::bigint AS segment_size,
7066
('x' || substring(pg_stat_archiver.last_archived_wal from 9 for 8))::bit(32)::int AS last_wal_div,
7167
('x' || substring(pg_stat_archiver.last_archived_wal from 17 for 8))::bit(32)::int AS last_wal_mod,
7268
CASE WHEN pg_is_in_recovery() THEN NULL ELSE
73-
('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 9 for 8))::bit(32)::int END AS current_wal_div,
69+
('x' || substring(pg_{1}_name(pg_current_{0}()) from 9 for 8))::bit(32)::int END AS current_wal_div,
7470
CASE WHEN pg_is_in_recovery() THEN NULL ELSE
75-
('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 17 for 8))::bit(32)::int END AS current_wal_mod
71+
('x' || substring(pg_{1}_name(pg_current_{0}()) from 17 for 8))::bit(32)::int END AS current_wal_mod
7672
FROM pg_settings, pg_stat_archiver
7773
WHERE pg_settings.name = 'wal_segment_size')
7874
SELECT greatest(coalesce((segment_parts_count - last_wal_mod) + ((current_wal_div - last_wal_div - 1) * segment_parts_count) + current_wal_mod - 1, 0), 0) AS count_files,
7975
greatest(coalesce(((segment_parts_count - last_wal_mod) + ((current_wal_div - last_wal_div - 1) * segment_parts_count) + current_wal_mod - 1) * segment_size, 0), 0) AS size_files
8076
FROM values;
81-
""")
77+
"""
78+
79+
self.disable_and_exit_if_archive_mode_is_not_on()
80+
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+
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'))
8288
result2 = Pooler.query("""SELECT archived_count, failed_count from pg_stat_archiver;""")
8389

8490
current_archived_count = result2[0][0]
@@ -164,10 +170,16 @@ def triggers(self, template, dashboard=False):
164170

165171
def keys_and_queries(self, template_zabbix):
166172
result = []
167-
result.append('{0}[*],$2 $1 -c "{1}"'.format(self.key.format("." + self.Items[0][0]),
168-
self.query_agent_count_files))
169-
result.append('{0}[*],$2 $1 -c "{1}"'.format(self.key.format("." + self.Items[1][0]),
170-
self.query_agent_size_files))
173+
if LooseVersion(self.VersionPG) >= LooseVersion('10'):
174+
result.append('{0}[*],$2 $1 -c "{1}"'.format(self.key.format("." + self.Items[0][0]),
175+
self.query_agent_count_files.format('wal_lsn', 'walfile')))
176+
result.append('{0}[*],$2 $1 -c "{1}"'.format(self.key.format("." + self.Items[1][0]),
177+
self.query_agent_size_files.format('wal_lsn', 'walfile')))
178+
else:
179+
result.append('{0}[*],$2 $1 -c "{1}"'.format(self.key.format("." + self.Items[0][0]),
180+
self.query_agent_count_files.format('xlog_location', 'xlogfile')))
181+
result.append('{0}[*],$2 $1 -c "{1}"'.format(self.key.format("." + self.Items[1][0]),
182+
self.query_agent_size_files.format('xlog_location', 'xlogfile')))
171183
result.append('{0}[*],$2 $1 -c "{1}"'.format(self.key.format("." + self.Items[2][0]),
172184
self.query_agent_archived_count))
173185
result.append('{0}[*],$2 $1 -c "{1}"'.format(self.key.format("." + self.Items[3][0]),

mamonsu/plugins/pgsql/xlog.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,27 +143,27 @@ def items(self, template, dashboard=False):
143143
'name': 'PostgreSQL: wal records generated',
144144
'key': self.right_type(self.key_wal_records),
145145
'value_type': self.VALUE_TYPE.numeric_unsigned,
146-
'delta': Plugin.DELTA_SPEED,
146+
'delta': delta,
147147
}) + template.item({
148148
'name': 'PostgreSQL: wal full page images generated',
149149
'key': self.right_type(self.key_wal_fpi),
150150
'value_type': self.VALUE_TYPE.numeric_unsigned,
151-
'delta': Plugin.DELTA_SPEED,
151+
'delta': delta,
152152
}) + template.item({
153153
'name': 'PostgreSQL: wal buffers full',
154154
'key': self.key_wal_buffers_full,
155155
'value_type': self.VALUE_TYPE.numeric_unsigned,
156-
'delta': Plugin.DELTA_CHANGE,
156+
'delta': delta,
157157
}) + template.item({
158158
'name': 'PostgreSQL: wal write time (ms)',
159159
'key': self.key_wal_write_time,
160160
'value_type': self.VALUE_TYPE.numeric_unsigned,
161-
'delta': Plugin.DELTA_CHANGE,
161+
'delta': delta,
162162
}) + template.item({
163163
'name': 'PostgreSQL: wal sync time (ms)',
164164
'key': self.key_wal_sync_time,
165165
'value_type': self.VALUE_TYPE.numeric_unsigned,
166-
'delta': Plugin.DELTA_CHANGE,
166+
'delta': delta,
167167
}) + template.item({
168168
'name': 'PostgreSQL: wal sync duty (%)',
169169
'key': self.key_wal_sync_duty,

mamonsu/tools/bootstrap/sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
RETURNS TABLE(COUNT_FILES BIGINT, SIZE_FILES BIGINT) AS $$
112112
WITH values AS (
113113
SELECT
114-
4096/(pg_settings.setting::bigint/1024/1024) AS segment_parts_count,
114+
4096/(coalesce(1, pg_settings.setting::bigint/1024/1024)) AS segment_parts_count,
115115
setting::bigint AS segment_size,
116116
('x' || substring(pg_stat_archiver.last_archived_wal from 9 for 8))::bit(32)::int AS last_wal_div,
117117
('x' || substring(pg_stat_archiver.last_archived_wal from 17 for 8))::bit(32)::int AS last_wal_mod,

0 commit comments

Comments
 (0)