Skip to content

Commit 90fea57

Browse files
committed
Added version 3.0.1:
- fixed PostgreSQL: Archive Command archive status graph y axis; - fixed #162 bootstrap -x option: now it checks installed extensions; - fixed #163 pgsql.count_files_to_archive and pgsql.size_files_to_archive items: now their evaluation depending on type of server (master or replica);
1 parent dc2c1ce commit 90fea57

File tree

10 files changed

+99
-83
lines changed

10 files changed

+99
-83
lines changed

mamonsu/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__author__ = 'Dmitry Vasilyev'
22
__author_email__ = '[email protected]'
33
__description__ = 'Monitoring agent for PostgreSQL'
4-
__version__ = '3.0.0'
4+
__version__ = '3.0.1'
55
__licence__ = 'BSD'
66

77
__url__ = 'https://github.com/postgrespro/mamonsu'

mamonsu/plugins/pgsql/archive_command.py

+47-54
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,39 @@ class ArchiveCommand(Plugin):
77
AgentPluginType = 'pg'
88
DEFAULT_CONFIG = {'max_count_files': str(2)}
99
Interval = 60
10+
11+
# if streaming replication is on, archive queue length and size will always be 0 for replicas
1012
query_agent_count_files = """
11-
WITH segment_parts_count AS
12-
(SELECT 4096/(setting::bigint/1024/1024) AS value FROM pg_settings
13-
WHERE name = 'wal_segment_size'),
14-
last_wal_div AS
15-
(SELECT ('x' || substring(last_archived_wal from 9 for 8))::bit(32)::int AS value
16-
FROM pg_stat_archiver),
17-
last_wal_mod AS
18-
(SELECT ('x' || substring(last_archived_wal from 17 for 8))::bit(32)::int AS value
19-
FROM pg_stat_archiver),
20-
current_wal_div AS
21-
(SELECT ('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 9 for 8))::bit(32)::int AS value),
22-
current_wal_mod AS
23-
(SELECT ('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 17 for 8))::bit(32)::int AS value)
24-
SELECT greatest(coalesce((segment_parts_count.value - last_wal_mod.value) + ((current_wal_div.value - last_wal_div.value - 1) * segment_parts_count.value) + current_wal_mod.value - 1, 0), 0)
25-
FROM segment_parts_count, last_wal_div, last_wal_mod, current_wal_div, current_wal_mod;
13+
WITH values AS (
14+
SELECT
15+
4096/(pg_settings.setting::bigint/1024/1024) AS segment_parts_count,
16+
setting::bigint AS segment_size,
17+
('x' || substring(pg_stat_archiver.last_archived_wal from 9 for 8))::bit(32)::int AS last_wal_div,
18+
('x' || substring(pg_stat_archiver.last_archived_wal from 17 for 8))::bit(32)::int AS last_wal_mod,
19+
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+
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+
FROM pg_settings, pg_stat_archiver
24+
WHERE pg_settings.name = 'wal_segment_size')
25+
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
26+
FROM values;
2627
"""
2728
query_agent_size_files = """
28-
WITH segment_parts_count AS
29-
(SELECT 4096/(setting::bigint/1024/1024) AS value FROM pg_settings
30-
WHERE name = 'wal_segment_size'),
31-
segment_size AS
32-
(SELECT setting::bigint AS value FROM pg_settings
33-
WHERE name = 'wal_segment_size'),
34-
last_wal_div AS
35-
(SELECT ('x' || substring(last_archived_wal from 9 for 8))::bit(32)::int AS value
36-
FROM pg_stat_archiver),
37-
last_wal_mod AS
38-
(SELECT ('x' || substring(last_archived_wal from 17 for 8))::bit(32)::int AS value
39-
FROM pg_stat_archiver),
40-
current_wal_div AS
41-
(SELECT ('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 9 for 8))::bit(32)::int AS value),
42-
current_wal_mod AS
43-
(SELECT ('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 17 for 8))::bit(32)::int AS value)
44-
SELECT greatest(coalesce(((segment_parts_count.value - last_wal_mod.value) + ((current_wal_div.value - last_wal_div.value - 1) * segment_parts_count.value) + current_wal_mod.value - 1) * segment_size.value, 0), 0)
45-
FROM segment_parts_count, segment_size, last_wal_div, last_wal_mod, current_wal_div, current_wal_mod;
29+
WITH values AS (
30+
SELECT
31+
4096/(pg_settings.setting::bigint/1024/1024) AS segment_parts_count,
32+
setting::bigint AS segment_size,
33+
('x' || substring(pg_stat_archiver.last_archived_wal from 9 for 8))::bit(32)::int AS last_wal_div,
34+
('x' || substring(pg_stat_archiver.last_archived_wal from 17 for 8))::bit(32)::int AS last_wal_mod,
35+
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+
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+
FROM pg_settings, pg_stat_archiver
40+
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+
FROM values;
4643
"""
4744

4845
query_agent_archived_count = "SELECT archived_count from pg_stat_archiver;"
@@ -52,9 +49,9 @@ class ArchiveCommand(Plugin):
5249
Items = [
5350
# key, desc, color, side, graph
5451
('count_files_to_archive', 'count files in archive_status need to archive', 'FFD700', 0, 1),
55-
('size_files_to_archive', 'size of files need to archive', '00FF00', 1, 0),
52+
('size_files_to_archive', 'size of files need to archive', '00FF00', 0, 0),
5653
('archived_files', 'count archived files', '00F000', 0, 1),
57-
('failed_trying_to_archive', 'count attempts to archive files', 'FF0000', 1, 1),
54+
('failed_trying_to_archive', 'count attempts to archive files', 'FF0000', 0, 1),
5855
]
5956
old_archived_count = None
6057
old_failed_count = None
@@ -66,25 +63,21 @@ def run(self, zbx):
6663
result1 = Pooler.query("""select * from mamonsu.archive_command_files()""")
6764
else:
6865
result1 = Pooler.query("""
69-
WITH segment_parts_count AS
70-
(SELECT 4096/(setting::bigint/1024/1024) AS value FROM pg_settings
71-
WHERE name = 'wal_segment_size'),
72-
segment_size AS
73-
(SELECT setting::bigint AS value FROM pg_settings
74-
WHERE name = 'wal_segment_size'),
75-
last_wal_div AS
76-
(SELECT ('x' || substring(last_archived_wal from 9 for 8))::bit(32)::int AS value
77-
FROM pg_stat_archiver),
78-
last_wal_mod AS
79-
(SELECT ('x' || substring(last_archived_wal from 17 for 8))::bit(32)::int AS value
80-
FROM pg_stat_archiver),
81-
current_wal_div AS
82-
(SELECT ('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 9 for 8))::bit(32)::int AS value),
83-
current_wal_mod AS
84-
(SELECT ('x' || substring(pg_walfile_name(pg_current_wal_lsn()) from 17 for 8))::bit(32)::int AS value)
85-
SELECT greatest(coalesce((segment_parts_count.value - last_wal_mod.value) + ((current_wal_div.value - last_wal_div.value - 1) * segment_parts_count.value) + current_wal_mod.value - 1, 0), 0) AS count_files,
86-
greatest(coalesce(((segment_parts_count.value - last_wal_mod.value) + ((current_wal_div.value - last_wal_div.value - 1) * segment_parts_count.value) + current_wal_mod.value - 1) * segment_size.value, 0), 0) AS size_files
87-
FROM segment_parts_count, segment_size, last_wal_div, last_wal_mod, current_wal_div, current_wal_mod;
66+
WITH values AS (
67+
SELECT
68+
4096/(pg_settings.setting::bigint/1024/1024) AS segment_parts_count,
69+
setting::bigint AS segment_size,
70+
('x' || substring(pg_stat_archiver.last_archived_wal from 9 for 8))::bit(32)::int AS last_wal_div,
71+
('x' || substring(pg_stat_archiver.last_archived_wal from 17 for 8))::bit(32)::int AS last_wal_mod,
72+
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,
74+
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
76+
FROM pg_settings, pg_stat_archiver
77+
WHERE pg_settings.name = 'wal_segment_size')
78+
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,
79+
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
80+
FROM values;
8881
""")
8982
result2 = Pooler.query("""SELECT archived_count, failed_count from pg_stat_archiver;""")
9083

mamonsu/tools/bootstrap/sql.py

+19-10
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,27 @@
156156
"""
157157

158158
CreateSchemaExtensionSQL = """
159-
CREATE EXTENSION pg_buffercache WITH SCHEMA mamonsu;
160-
"""
161-
162-
CreateExtensionFunctionsSQL = """
163-
CREATE OR REPLACE FUNCTION mamonsu.buffer_cache()
159+
DO
160+
$do$
161+
DECLARE
162+
pg_buffercache_schema text;
163+
BEGIN
164+
CREATE EXTENSION IF NOT EXISTS pg_buffercache WITH SCHEMA mamonsu;
165+
SELECT n.nspname INTO pg_buffercache_schema
166+
FROM pg_extension e
167+
JOIN pg_namespace n
168+
ON e.extnamespace = n.oid
169+
WHERE e.extname = 'pg_buffercache';
170+
EXECUTE 'CREATE OR REPLACE FUNCTION mamonsu.buffer_cache()
164171
RETURNS TABLE(SIZE BIGINT, TWICE_USED BIGINT, DIRTY BIGINT) AS $$
165172
SELECT
166-
SUM(1) * (current_setting('block_size')::int8),
167-
SUM(CASE WHEN usagecount > 1 THEN 1 ELSE 0 END) * (current_setting('block_size')::int8),
168-
SUM(CASE isdirty WHEN true THEN 1 ELSE 0 END) * (current_setting('block_size')::int8)
169-
FROM mamonsu.pg_buffercache
170-
$$ LANGUAGE SQL SECURITY DEFINER;
173+
SUM(1) * (current_setting(''block_size'')::int8),
174+
SUM(CASE WHEN usagecount > 1 THEN 1 ELSE 0 END) * (current_setting(''block_size'')::int8),
175+
SUM(CASE isdirty WHEN true THEN 1 ELSE 0 END) * (current_setting(''block_size'')::int8)
176+
FROM ' || pg_buffercache_schema || '.pg_buffercache
177+
$$ LANGUAGE SQL SECURITY DEFINER;';
178+
END
179+
$do$;
171180
"""
172181

173182
GrantsOnDefaultSchemaSQL = """

mamonsu/tools/bootstrap/start.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from mamonsu import __version__ as mamonsu_version
1111
from mamonsu.lib.default_config import DefaultConfig
1212
from mamonsu.plugins.pgsql.pool import Pooler
13-
from mamonsu.tools.bootstrap.sql import CreateMamonsuUserSQL, CreateSchemaExtensionSQL, CreateExtensionFunctionsSQL, \
13+
from mamonsu.tools.bootstrap.sql import CreateMamonsuUserSQL, CreateSchemaExtensionSQL, \
1414
CreateSchemaDefaultSQL,GrantsOnDefaultSchemaSQL, GrantsOnExtensionSchemaSQL, QuerySplit
1515

1616

@@ -226,18 +226,9 @@ def run_deploy():
226226
Pooler.query(bootstrap_extension_queries)
227227
except Exception as e:
228228
sys.stderr.write(
229-
"Bootstrap failed to create pg_buffercache extension.\n"
229+
"Bootstrap failed to create pg_buffercache extension and functions.\n"
230230
"Error: {0}\n".format(e))
231-
sys.stderr.write("Please install pg_buffercache extension and rerun bootstrap "
232-
"if you want to get metrics from pg_buffercache view. \n")
233-
try:
234-
bootstrap_extension_queries = fill_query_params(CreateExtensionFunctionsSQL)
235-
Pooler.query(bootstrap_extension_queries)
236-
except Exception as e:
237-
sys.stderr.write(
238-
"Bootstrap failed to create the function which required pg_buffercache extension.\n"
239-
"Error: {0}\n".format(e))
240-
sys.stderr.write("Please install pg_buffercache extension and rerun bootstrap "
231+
sys.stderr.write("Please install pg_buffercache extension manually and rerun bootstrap "
241232
"if you want to get metrics from pg_buffercache view. \n")
242233

243234
try:

packaging/debian/changelog

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
mamonsu (3.0.1-1) stable; urgency=low
2+
* fixed 'PostgreSQL: Archive Command archive status' graph y axis
3+
* fixed bootstrap -x option: now it checks installed extensions
4+
* fixed 'pgsql.count_files_to_archive' and 'pgsql.size_files_to_archive' items: now their evaluation depending on type of server (master or replica)
5+
16
mamonsu (3.0.0-1) stable; urgency=low
27
* change template name to 'Mamonsu PostgreSQL [PLATFORM]'
38
* change metric name 'PostgreSQL transactions: total' to 'PostgreSQL transactions: committed'

packaging/rpm/SPECS/mamonsu.alt.spec

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
33

44
Name: mamonsu
5-
Version: 3.0.0
5+
Version: 3.0.1
66
Release: 1%{?dist}
77
Summary: Monitoring agent for PostgreSQL
88
Group: Applications/Internet
@@ -73,7 +73,13 @@ chown mamonsu.mamonsu /var/log/mamonsu
7373
/sbin/chkconfig --del mamonsu
7474

7575
%changelog
76-
* Mon Aug 16 2021 Alexandra Kuznetsova <@a.kuznetsova> - 3.0.0-1
76+
* Mon Sep 6 2021 Alexandra Kuznetsova <[email protected]> - 3.0.1-1
77+
- fixed 'PostgreSQL: Archive Command archive status' graph y axis
78+
- fixed bootstrap -x option: now it checks installed extensions
79+
- fixed 'pgsql.count_files_to_archive' and 'pgsql.size_files_to_archive' items: now their evaluation depending on type of server (master or replica)
80+
81+
%changelog
82+
* Mon Aug 16 2021 Alexandra Kuznetsova <[email protected]> - 3.0.0-1
7783
- change template name to 'Mamonsu PostgreSQL [PLATFORM]'
7884
- change metric name 'PostgreSQL transactions: total' to 'PostgreSQL transactions: committed'
7985
- fix Cache Hit Ratio metric calculating

packaging/rpm/SPECS/mamonsu.spec

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Name: mamonsu
2-
Version: 3.0.0
2+
Version: 3.0.1
33
Release: 1%{?dist}
44
Summary: Monitoring agent for PostgreSQL
55
Group: Applications/Internet
@@ -70,7 +70,13 @@ chown mamonsu.mamonsu /var/log/mamonsu
7070
/sbin/chkconfig --del mamonsu
7171

7272
%changelog
73-
* Mon Aug 16 2021 Alexandra Kuznetsova <@a.kuznetsova> - 3.0.0-1
73+
* Mon Sep 6 2021 Alexandra Kuznetsova <[email protected]> - 3.0.1-1
74+
- fixed 'PostgreSQL: Archive Command archive status' graph y axis
75+
- fixed bootstrap -x option: now it checks installed extensions
76+
- fixed 'pgsql.count_files_to_archive' and 'pgsql.size_files_to_archive' items: now their evaluation depending on type of server (master or replica)
77+
78+
%changelog
79+
* Mon Aug 16 2021 Alexandra Kuznetsova <[email protected]> - 3.0.0-1
7480
- change template name to 'Mamonsu PostgreSQL [PLATFORM]'
7581
- change metric name 'PostgreSQL transactions: total' to 'PostgreSQL transactions: committed'
7682
- fix Cache Hit Ratio metric calculating

packaging/rpm/SPECS/mamonsu.suse.spec

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%define _datarootdir %{_prefix}/share
22
Name: mamonsu
3-
Version: 3.0.0
3+
Version: 3.0.1
44
Release: 1%{?dist}
55
Summary: Monitoring agent for PostgreSQL
66
Group: Applications/Internet
@@ -74,7 +74,13 @@ chown mamonsu.mamonsu /var/log/mamonsu
7474
/sbin/chkconfig --del mamonsu
7575

7676
%changelog
77-
* Mon Aug 16 2021 Alexandra Kuznetsova <@a.kuznetsova> - 3.0.0-1
77+
* Mon Sep 6 2021 Alexandra Kuznetsova <[email protected]> - 3.0.1-1
78+
- fixed 'PostgreSQL: Archive Command archive status' graph y axis
79+
- fixed bootstrap -x option: now it checks installed extensions
80+
- fixed 'pgsql.count_files_to_archive' and 'pgsql.size_files_to_archive' items: now their evaluation depending on type of server (master or replica)
81+
82+
%changelog
83+
* Mon Aug 16 2021 Alexandra Kuznetsova <[email protected]> - 3.0.0-1
7884
- change template name to 'Mamonsu PostgreSQL [PLATFORM]'
7985
- change metric name 'PostgreSQL transactions: total' to 'PostgreSQL transactions: committed'
8086
- fix Cache Hit Ratio metric calculating

0 commit comments

Comments
 (0)