@@ -12,21 +12,32 @@ class Connections(Plugin):
12
12
DEFAULT_CONFIG = {
13
13
"percent_connections_tr" : str (90 )
14
14
}
15
- # (state, key, name, graph)
15
+ # (state, key, name, graph item color )
16
16
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" ),
19
19
("idle in transaction" , "idle_in_transaction" ,
20
- "number of idle in transaction connections" , "CC00CC" ),
20
+ "number of user idle in transaction connections" , "CC00CC" ),
21
21
("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" ),
23
23
("fastpath function call" , "fastpath_function_call" ,
24
- "number of fastpath function call" , "CCCC00" ),
24
+ "number of user fastpath function call connections " , "CCCC00" ),
25
25
("disabled" , "disabled" ,
26
- "number of disabled" ,
26
+ "number of user disabled connections " ,
27
27
"00CCCC" )
28
28
]
29
29
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
+
30
41
Max_connections = None
31
42
32
43
query_agent = """
@@ -123,14 +134,18 @@ def run(self, zbx):
123
134
self .Max_connections = result [0 ][0 ]
124
135
zbx .send ("pgsql.connections[max_connections]" , int (self .Max_connections ))
125
136
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
+
126
141
def items (self , template , dashboard = False ):
127
142
result = template .item ({
128
- "name" : "PostgreSQL: number of total connections" ,
143
+ "name" : "PostgreSQL: number of user total connections" ,
129
144
"key" : self .right_type (self .key , "total" ),
130
145
"delay" : self .plugin_config ("interval" )
131
146
})
132
147
result += template .item ({
133
- "name" : "PostgreSQL: number of waiting connections" ,
148
+ "name" : "PostgreSQL: number of user waiting connections" ,
134
149
"key" : self .right_type (self .key , "waiting" ),
135
150
"delay" : self .plugin_config ("interval" )
136
151
})
@@ -146,6 +161,14 @@ def items(self, template, dashboard=False):
146
161
"key" : self .right_type (self .key , item [1 ]),
147
162
"delay" : self .plugin_config ("interval" )
148
163
})
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
+
149
172
if not dashboard :
150
173
return result
151
174
else :
@@ -160,20 +183,28 @@ def graphs(self, template, dashboard=False):
160
183
})
161
184
items .append ({
162
185
"key" : self .right_type (self .key , "total" ),
163
- "color" : "EEEEEE "
186
+ "color" : "BB0000 "
164
187
})
165
188
items .append ({
166
189
"key" : self .right_type (self .key , "waiting" ),
167
- "color" : "BB0000 "
190
+ "color" : "546E7A "
168
191
})
169
192
items .append ({
170
193
"key" : self .right_type (self .key , "max_connections" ),
171
- "color" : "00BB00 "
194
+ "color" : "067845 "
172
195
})
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
+
173
203
graph = {
174
204
"name" : "PostgreSQL connections" ,
175
205
"items" : items
176
206
}
207
+
177
208
if not dashboard :
178
209
return template .graph (graph )
179
210
else :
@@ -218,5 +249,9 @@ def keys_and_queries(self, template_zabbix):
218
249
"(backend_type = 'client backend' OR backend_type = 'parallel worker')" if LooseVersion (
219
250
self .VersionPG ) >= LooseVersion (
220
251
"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 ))))
221
256
result .append ("{0}[*],$2 $1 -c \" {1}\" " .format (self .key .format (".max_connections" ), self .query_agent_max_conn ))
222
257
return template_zabbix .key_and_query (result )
0 commit comments