Skip to content

Commit f11bbfb

Browse files
committed
feat: add metric and trigger for number of non-active replication slots
1 parent 30f08ad commit f11bbfb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

mamonsu/plugins/pgsql/xlog.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from distutils.version import LooseVersion
55
from .pool import Pooler
66

7+
NUMBER_NON_ACTIVE_SLOTS = 0
78

89
class Xlog(Plugin):
910
DEFAULT_CONFIG = {'lag_more_than_in_sec': str(60 * 5)}
@@ -30,6 +31,7 @@ class Xlog(Plugin):
3031
key_wall = 'pgsql.wal.write{0}'
3132
key_count_wall = "pgsql.wal.count{0}"
3233
key_replication = "pgsql.replication_lag{0}"
34+
key_non_active_slots = "pgsql.replication.non_active_slots"
3335
AgentPluginType = 'pg'
3436

3537
def run(self, zbx):
@@ -80,6 +82,9 @@ def run(self, zbx):
8082
result = Pooler.run_sql_type('count_xlog_files')
8183
zbx.send(self.key_count_wall.format("[]"), int(result[0][0]))
8284

85+
non_active_slots = Pooler.run_sql_type("select count(*) from pg_replication_slots where active = false;")
86+
zbx.send(self.key_non_active_slots.format("[]"), int(non_active_slots[0][0]))
87+
8388
def items(self, template):
8489
result = ''
8590
if self.Type == "mamonsu":
@@ -100,6 +105,10 @@ def items(self, template):
100105
'name': 'PostgreSQL: count of xlog files',
101106
'key': self.right_type(self.key_count_wall),
102107
'delay': self.plugin_config('interval')
108+
}) + template.item({
109+
'name': 'PostgreSQL: count non-active replication slots',
110+
'key': self.right_type(self.key_non_active_slots),
111+
'value_type': self.VALUE_TYPE.numeric_unsigned,
103112
})
104113
return result
105114

@@ -122,12 +131,18 @@ def graphs(self, template):
122131
return result
123132

124133
def triggers(self, template):
125-
return template.trigger({
134+
triggers = template.trigger({
126135
'name': 'PostgreSQL streaming lag too high '
127136
'on {HOSTNAME} (value={ITEM.LASTVALUE})',
128137
'expression': '{#TEMPLATE:' + self.right_type(self.key_replication, "sec") + '.last()}>' +
129138
self.plugin_config('lag_more_than_in_sec')
139+
}) + template.trigger({
140+
'name': 'PostgreSQL number of non-active replication slots '
141+
'on {HOSTNAME} (value={ITEM.LASTVALUE})',
142+
'expression': '{#TEMPLATE:' + self.right_type(self.key_replication, "sec") + '.last()}≠' +
143+
NUMBER_NON_ACTIVE_SLOTS
130144
})
145+
return triggers
131146

132147
def discovery_rules(self, template):
133148
rule = {

0 commit comments

Comments
 (0)