44from distutils .version import LooseVersion
55from .pool import Pooler
66
7+ NUMBER_NON_ACTIVE_SLOTS = 0
8+
79
810class Xlog (Plugin ):
911 DEFAULT_CONFIG = {'lag_more_than_in_sec' : str (60 * 5 )}
@@ -30,6 +32,7 @@ class Xlog(Plugin):
3032 key_wall = 'pgsql.wal.write{0}'
3133 key_count_wall = "pgsql.wal.count{0}"
3234 key_replication = "pgsql.replication_lag{0}"
35+ key_non_active_slots = "pgsql.replication.non_active_slots{0}"
3336 AgentPluginType = 'pg'
3437
3538 def run (self , zbx ):
@@ -80,6 +83,9 @@ def run(self, zbx):
8083 result = Pooler .run_sql_type ('count_xlog_files' )
8184 zbx .send (self .key_count_wall .format ("[]" ), int (result [0 ][0 ]))
8285
86+ non_active_slots = Pooler .query ("""SELECT count(*) FROM pg_replication_slots WHERE active = 'false';""" )
87+ zbx .send (self .key_non_active_slots .format ("[]" ), int (non_active_slots [0 ][0 ]))
88+
8389 def items (self , template ):
8490 result = ''
8591 if self .Type == "mamonsu" :
@@ -100,6 +106,10 @@ def items(self, template):
100106 'name' : 'PostgreSQL: count of xlog files' ,
101107 'key' : self .right_type (self .key_count_wall ),
102108 'delay' : self .plugin_config ('interval' )
109+ }) + template .item ({
110+ 'name' : 'PostgreSQL: count non-active replication slots' ,
111+ 'key' : self .right_type (self .key_non_active_slots ),
112+ 'value_type' : self .VALUE_TYPE .numeric_unsigned ,
103113 })
104114 return result
105115
@@ -122,12 +132,18 @@ def graphs(self, template):
122132 return result
123133
124134 def triggers (self , template ):
125- return template .trigger ({
135+ triggers = template .trigger ({
126136 'name' : 'PostgreSQL streaming lag too high '
127137 'on {HOSTNAME} (value={ITEM.LASTVALUE})' ,
128138 'expression' : '{#TEMPLATE:' + self .right_type (self .key_replication , "sec" ) + '.last()}>' +
129139 self .plugin_config ('lag_more_than_in_sec' )
140+ }) + template .trigger ({
141+ 'name' : 'PostgreSQL number of non-active replication slots '
142+ 'on {HOSTNAME} (value={ITEM.LASTVALUE})' ,
143+ 'expression' : '{#TEMPLATE:' + self .right_type (self .key_non_active_slots ) + '.last()}#' +
144+ str (NUMBER_NON_ACTIVE_SLOTS )
130145 })
146+ return triggers
131147
132148 def discovery_rules (self , template ):
133149 rule = {
0 commit comments