44from .pool import Pooler
55from mamonsu .lib .zbx_template import ZbxTemplate
66
7+
78class Autovacuum (Plugin ):
8-
99 AgentPluginType = "pg"
1010 # TODO: unify keys and remove its direct mentioning in zbx.send() functions
1111 key_count = "pgsql.autovacuum.count{0}"
@@ -21,7 +21,8 @@ class Autovacuum(Plugin):
2121 def run (self , zbx ):
2222 if Pooler .server_version_greater ("10.0" ):
2323 result_count = Pooler .run_sql_type ("count_autovacuum" , args = ["backend_type = 'autovacuum worker'" ])
24- result_utilization = Pooler .run_sql_type ("autovacuum_utilization" , args = ["backend_type = 'autovacuum worker'" ])
24+ result_utilization = Pooler .run_sql_type ("autovacuum_utilization" ,
25+ args = ["backend_type = 'autovacuum worker'" ])
2526 else :
2627 result_count = Pooler .run_sql_type ("count_autovacuum" , args = [
2728 "query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()" ])
@@ -51,7 +52,7 @@ def items(self, template, dashboard=False):
5152 "value_type" : Plugin .VALUE_TYPE .numeric_float ,
5253 "units" : Plugin .UNITS .percent ,
5354 "type" : Plugin .TYPE .CALCULATED ,
54- "params" : "avg(pgsql.autovacuum.utilization[] , 5m)" ,
55+ "params" : "avg({item} , 5m)" . format ( item = self . key_utilization . format ( "[]" )) ,
5556 "delay" : self .plugin_config ("interval" )
5657 }))
5758 result += (template .item ({
@@ -60,7 +61,7 @@ def items(self, template, dashboard=False):
6061 "value_type" : Plugin .VALUE_TYPE .numeric_float ,
6162 "units" : Plugin .UNITS .percent ,
6263 "type" : Plugin .TYPE .CALCULATED ,
63- "params" : "avg(pgsql.autovacuum.utilization[] , 15m)" ,
64+ "params" : "avg({item} , 15m)" . format ( item = self . key_utilization . format ( "[]" )) ,
6465 "delay" : self .plugin_config ("interval" )
6566 }))
6667 result += (template .item ({
@@ -69,13 +70,13 @@ def items(self, template, dashboard=False):
6970 "value_type" : Plugin .VALUE_TYPE .numeric_float ,
7071 "units" : Plugin .UNITS .percent ,
7172 "type" : Plugin .TYPE .CALCULATED ,
72- "params" : "avg(pgsql.autovacuum.utilization[] , 30m)" ,
73+ "params" : "avg({item} , 30m)" . format ( item = self . key_utilization . format ( "[]" )) ,
7374 "delay" : self .plugin_config ("interval" )
7475 }))
7576 return result
7677 else :
7778 return []
78-
79+
7980 def graphs (self , template , dashboard = False ):
8081 result = template .graph ({
8182 "name" : "PostgreSQL Autovacuum: Count of Autovacuum Workers" ,
@@ -98,15 +99,17 @@ def graphs(self, template, dashboard=False):
9899 def keys_and_queries (self , template_zabbix ):
99100 result = []
100101 if LooseVersion (self .VersionPG ) >= LooseVersion ("10" ):
101- result .append ("{0},$2 $1 -c \" {1}\" " .format (self .key_count .format ("[*]" ),
102- Pooler .SQL ["count_autovacuum" ][0 ].format ("backend_type = 'autovacuum worker'" )))
103- result .append ("{0},$2 $1 -c \" {1}\" " .format (self .key_utilization .format ("[*]" ),
104- Pooler .SQL ["autovacuum_utilization" ][0 ].format (
105- "backend_type = 'autovacuum worker'" )))
102+ result .append ("{0},$2 $1 -Aqtc \" {1}\" " .format (self .key_count .format ("[*]" ),
103+ Pooler .SQL ["count_autovacuum" ][0 ].format (
104+ "backend_type = 'autovacuum worker'" )))
105+ result .append ("{0},$2 $1 -Aqtc \" {1}\" " .format (self .key_utilization .format ("[*]" ),
106+ Pooler .SQL ["autovacuum_utilization" ][0 ].format (
107+ "backend_type = 'autovacuum worker'" )))
106108 else :
107- result .append ("{0},$2 $1 -c \" {1}\" " .format (self .key_count .format ("[*]" ),
108- Pooler .SQL ["count_autovacuum" ][0 ].format ("query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()" )))
109- result .append ("{0},$2 $1 -c \" {1}\" " .format (self .key_utilization .format ("[*]" ),
110- Pooler .SQL ["autovacuum_utilization" ][0 ].format (
111- "query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()" )))
109+ result .append ("{0},$2 $1 -Aqtc \" {1}\" " .format (self .key_count .format ("[*]" ),
110+ Pooler .SQL ["count_autovacuum" ][0 ].format (
111+ "query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()" )))
112+ result .append ("{0},$2 $1 -Aqtc \" {1}\" " .format (self .key_utilization .format ("[*]" ),
113+ Pooler .SQL ["autovacuum_utilization" ][0 ].format (
114+ "query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()" )))
112115 return template_zabbix .key_and_query (result )
0 commit comments