@@ -12,21 +12,32 @@ class Connections(Plugin):
1212 DEFAULT_CONFIG = {
1313 "percent_connections_tr" : str (90 )
1414 }
15- # (state, key, name, graph)
15+ # (state, key, name, graph item color )
1616 Items = [
17- ("active" , "active" , "number of active connections" , "00BB00" ),
18- ("idle" , "idle" , "number of idle connections" , "0000BB" ),
17+ ("active" , "active" , "number of active user connections" , "00BB00" ),
18+ ("idle" , "idle" , "number of idle user connections" , "0000BB" ),
1919 ("idle in transaction" , "idle_in_transaction" ,
20- "number of idle in transaction connections" , "CC00CC" ),
20+ "number of user idle in transaction connections" , "CC00CC" ),
2121 ("idle in transaction (aborted)" , "idle_in_transaction_aborted" ,
22- "number of idle in transaction (aborted)" , "CCCCCC" ),
22+ "number of user idle in transaction (aborted) connections " , "CCCCCC" ),
2323 ("fastpath function call" , "fastpath_function_call" ,
24- "number of fastpath function call" , "CCCC00" ),
24+ "number of user fastpath function call connections " , "CCCC00" ),
2525 ("disabled" , "disabled" ,
26- "number of disabled" ,
26+ "number of user disabled connections " ,
2727 "00CCCC" )
2828 ]
2929
30+ # for PG 10+
31+ default_backend_types = ["archiver" , "autovacuum launcher" , "autovacuum worker" , "background worker" ,
32+ "background writer" , "client backend" , "checkpointer" , "logical replication launcher" ,
33+ "logical replication worker" , "parallel worker" , "startup" , "walreceiver" , "walsender" ,
34+ "walwriter" ]
35+ query_other_connections = """
36+ SELECT coalesce(count(*), 0)
37+ FROM pg_catalog.pg_stat_activity
38+ WHERE (backend_type NOT IN ('{0}'));
39+ """ .format ("', '" .join (default_backend_types ))
40+
3041 Max_connections = None
3142
3243 query_agent = """
@@ -123,14 +134,18 @@ def run(self, zbx):
123134 self .Max_connections = result [0 ][0 ]
124135 zbx .send ("pgsql.connections[max_connections]" , int (self .Max_connections ))
125136
137+ if Pooler .server_version_greater ("10.0" ):
138+ result = Pooler .query (self .query_other_connections )
139+ zbx .send ("pgsql.connections[other]" , int (result [0 ][0 ]))
140+
126141 def items (self , template , dashboard = False ):
127142 result = template .item ({
128- "name" : "PostgreSQL: number of total connections" ,
143+ "name" : "PostgreSQL: number of user total connections" ,
129144 "key" : self .right_type (self .key , "total" ),
130145 "delay" : self .plugin_config ("interval" )
131146 })
132147 result += template .item ({
133- "name" : "PostgreSQL: number of waiting connections" ,
148+ "name" : "PostgreSQL: number of user waiting connections" ,
134149 "key" : self .right_type (self .key , "waiting" ),
135150 "delay" : self .plugin_config ("interval" )
136151 })
@@ -146,6 +161,14 @@ def items(self, template, dashboard=False):
146161 "key" : self .right_type (self .key , item [1 ]),
147162 "delay" : self .plugin_config ("interval" )
148163 })
164+
165+ if Pooler .server_version_greater ("10.0" ):
166+ result += template .item ({
167+ "name" : "PostgreSQL: number of other connections" ,
168+ "key" : self .right_type (self .key , "other" ),
169+ "delay" : self .plugin_config ("interval" )
170+ })
171+
149172 if not dashboard :
150173 return result
151174 else :
@@ -160,20 +183,28 @@ def graphs(self, template, dashboard=False):
160183 })
161184 items .append ({
162185 "key" : self .right_type (self .key , "total" ),
163- "color" : "EEEEEE "
186+ "color" : "BB0000 "
164187 })
165188 items .append ({
166189 "key" : self .right_type (self .key , "waiting" ),
167- "color" : "BB0000 "
190+ "color" : "546E7A "
168191 })
169192 items .append ({
170193 "key" : self .right_type (self .key , "max_connections" ),
171- "color" : "00BB00 "
194+ "color" : "067845 "
172195 })
196+
197+ if Pooler .server_version_greater ("10.0" ):
198+ items .append ({
199+ "key" : self .right_type (self .key , "other" ),
200+ "color" : "8D6E63"
201+ })
202+
173203 graph = {
174204 "name" : "PostgreSQL connections" ,
175205 "items" : items
176206 }
207+
177208 if not dashboard :
178209 return template .graph (graph )
179210 else :
@@ -218,5 +249,9 @@ def keys_and_queries(self, template_zabbix):
218249 "(backend_type = 'client backend' OR backend_type = 'parallel worker')" if LooseVersion (
219250 self .VersionPG ) >= LooseVersion (
220251 "10" ) else "state IS NOT NULL" )))
252+ if LooseVersion (self .VersionPG ) >= LooseVersion ("10" ):
253+ result .append ("{0}[*],$2 $1 -c \" {1}\" " .format (self .key .format (".other" ),
254+ self .query_other_connections .format (
255+ "', '" .join (self .default_backend_types ))))
221256 result .append ("{0}[*],$2 $1 -c \" {1}\" " .format (self .key .format (".max_connections" ), self .query_agent_max_conn ))
222257 return template_zabbix .key_and_query (result )
0 commit comments