Skip to content

Commit f6dd9fb

Browse files
author
alexander popov
committed
feat: add a new plugin. The plugin show age in second and number of transactions that are currently prepared for two-phase commit. Plugin has graphs and prigger
1 parent f015067 commit f6dd9fb

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

mamonsu/plugins/pgsql/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
__all__ += ['cfs']
66
__all__ += ['archive_command']
77
__all__ += ['relations_size']
8+
__all__ += ['prepared_transaction']
89

910
from . import *

mamonsu/plugins/pgsql/relations_size.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ def run(self, zbx):
8282

8383
zbx.send('pgsql.relation.size[]', zbx.json({'data': rels}))
8484

85-
86-
def items(self, template):
87-
88-
return ''
89-
9085
def discovery_rules(self, template):
9186
rule = {
9287
'name': 'Relation size discovery',

mamonsu/tools/bootstrap/sql.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@
117117
RETURNS TABLE(SETTING TEXT) AS $$
118118
select setting from pg_catalog.pg_settings where name = param
119119
$$ LANGUAGE SQL SECURITY DEFINER;
120+
121+
CREATE OR REPLACE FUNCTION public.mamonsu_prepared_transaction()
122+
RETURNS TABLE(count_prepared BIGINT, oldest_prepared BIGINT) AS $$
123+
SELECT COUNT(*) AS count_prepared,
124+
coalesce (ROUND(MAX(EXTRACT (EPOCH FROM (now() - prepared)))),0)::bigint AS oldest_prepared
125+
FROM pg_catalog.pg_prepared_xacts$$ LANGUAGE SQL SECURITY DEFINER;
120126
"""
121127

122128
GrantsOnSchemaSQL = """
@@ -145,4 +151,6 @@
145151
GRANT EXECUTE ON FUNCTION public.mamonsu_get_sys_param(param text) TO {1};
146152
147153
GRANT EXECUTE ON FUNCTION public.mamonsu_get_connections_states() TO {1};
154+
155+
GRANT EXECUTE ON FUNCTION public.mamonsu_prepared_transaction() TO {1};
148156
"""

packaging/conf/example.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,11 @@ enabled = False
178178
relations=pg_catalog.pg_class,pg_catalog.pg_user
179179
interval = 500
180180

181+
# Get age in second and number of transactions that are currently prepared for two-phase commit.
182+
# https://www.postgresql.org/docs/current/sql-prepare-transaction.html
183+
# https://www.postgresql.org/docs/12/view-pg-prepared-xacts.html
184+
# max_prepared_transaction_time - age of prepared pransaction in second, after which the trigger run.
185+
# (возраст подготовленных транзакций, после которого срабатывает триггер.) ????
186+
[preparedtransaction]
187+
max_prepared_transaction_time = 60
188+
interval = 60

0 commit comments

Comments
 (0)