4
4
from distutils .version import LooseVersion
5
5
from .pool import Pooler
6
6
7
+ NUMBER_NON_ACTIVE_SLOTS = 0
8
+
7
9
8
10
class Xlog (Plugin ):
9
11
DEFAULT_CONFIG = {'lag_more_than_in_sec' : str (60 * 5 )}
@@ -30,6 +32,7 @@ class Xlog(Plugin):
30
32
key_wall = 'pgsql.wal.write{0}'
31
33
key_count_wall = "pgsql.wal.count{0}"
32
34
key_replication = "pgsql.replication_lag{0}"
35
+ key_non_active_slots = "pgsql.replication.non_active_slots{0}"
33
36
AgentPluginType = 'pg'
34
37
35
38
def run (self , zbx ):
@@ -80,6 +83,9 @@ def run(self, zbx):
80
83
result = Pooler .run_sql_type ('count_xlog_files' )
81
84
zbx .send (self .key_count_wall .format ("[]" ), int (result [0 ][0 ]))
82
85
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
+
83
89
def items (self , template ):
84
90
result = ''
85
91
if self .Type == "mamonsu" :
@@ -100,6 +106,10 @@ def items(self, template):
100
106
'name' : 'PostgreSQL: count of xlog files' ,
101
107
'key' : self .right_type (self .key_count_wall ),
102
108
'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 ,
103
113
})
104
114
return result
105
115
@@ -122,12 +132,18 @@ def graphs(self, template):
122
132
return result
123
133
124
134
def triggers (self , template ):
125
- return template .trigger ({
135
+ triggers = template .trigger ({
126
136
'name' : 'PostgreSQL streaming lag too high '
127
137
'on {HOSTNAME} (value={ITEM.LASTVALUE})' ,
128
138
'expression' : '{#TEMPLATE:' + self .right_type (self .key_replication , "sec" ) + '.last()}>' +
129
139
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 )
130
145
})
146
+ return triggers
131
147
132
148
def discovery_rules (self , template ):
133
149
rule = {
0 commit comments