77class Autovacuum (Plugin ):
88
99 AgentPluginType = "pg"
10- key = "pgsql.autovacuum.count{0}"
10+ # TODO: unify keys and remove its direct mentioning in zbx.send() functions
11+ key_count = "pgsql.autovacuum.count{0}"
12+ key_utilization = "pgsql.autovacuum.utilization{0}"
13+ key_utilization_avg5 = "pgsql.autovacuum.utilization.avg5{0}"
14+ key_utilization_avg15 = "pgsql.autovacuum.utilization.avg15{0}"
15+ key_utilization_avg30 = "pgsql.autovacuum.utilization.avg30{0}"
16+
17+ DEFAULT_CONFIG = {
18+ "interval" : str (60 )
19+ }
1120
1221 def run (self , zbx ):
1322 if Pooler .server_version_greater ("10.0" ):
14- result = Pooler .run_sql_type ("count_autovacuum" , args = ["backend_type = 'autovacuum worker'" ])
23+ 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'" ])
1525 else :
16- result = Pooler .run_sql_type ("count_autovacuum" , args = [
26+ result_count = Pooler .run_sql_type ("count_autovacuum" , args = [
1727 "query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()" ])
18- zbx .send ("pgsql.autovacuum.count[]" , int (result [0 ][0 ]))
19-
28+ result_utilization = Pooler .run_sql_type ("autovacuum_utilization" , args = [
29+ "query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()" ])
30+ zbx .send ("pgsql.autovacuum.count[]" , int (result_count [0 ][0 ]))
31+ zbx .send ("pgsql.autovacuum.utilization[]" , int (result_utilization [0 ][0 ]))
32+
2033 def items (self , template , dashboard = False ):
34+ result = ""
2135 if not dashboard :
22- return template .item ({
36+ result += ( template .item ({
2337 "name" : "PostgreSQL Autovacuum: Count of Autovacuum Workers" ,
24- "key" : self .right_type (self .key ),
38+ "key" : self .right_type (self .key_count ),
39+ "delay" : self .plugin_config ("interval" )
40+ }))
41+ result += (template .item ({
42+ "name" : "PostgreSQL Autovacuum: Utilization per {0} seconds" .format (self .plugin_config ("interval" )),
43+ "key" : self .right_type (self .key_utilization ),
44+ "value_type" : Plugin .VALUE_TYPE .numeric_float ,
45+ "units" : Plugin .UNITS .percent ,
2546 "delay" : self .plugin_config ("interval" )
26- })
47+ }))
48+ result += (template .item ({
49+ "name" : "PostgreSQL Autovacuum: Average Utilization per 5 minutes" ,
50+ "key" : self .right_type (self .key_utilization_avg5 ),
51+ "value_type" : Plugin .VALUE_TYPE .numeric_float ,
52+ "units" : Plugin .UNITS .percent ,
53+ "type" : Plugin .TYPE .CALCULATED ,
54+ "params" : "avg(pgsql.autovacuum.utilization[], 5m)" ,
55+ "delay" : self .plugin_config ("interval" )
56+ }))
57+ result += (template .item ({
58+ "name" : "PostgreSQL Autovacuum: Average Utilization per 15 minutes" ,
59+ "key" : self .right_type (self .key_utilization_avg15 ),
60+ "value_type" : Plugin .VALUE_TYPE .numeric_float ,
61+ "units" : Plugin .UNITS .percent ,
62+ "type" : Plugin .TYPE .CALCULATED ,
63+ "params" : "avg(pgsql.autovacuum.utilization[], 15m)" ,
64+ "delay" : self .plugin_config ("interval" )
65+ }))
66+ result += (template .item ({
67+ "name" : "PostgreSQL Autovacuum: Average Utilization per 30 minutes" ,
68+ "key" : self .right_type (self .key_utilization_avg30 ),
69+ "value_type" : Plugin .VALUE_TYPE .numeric_float ,
70+ "units" : Plugin .UNITS .percent ,
71+ "type" : Plugin .TYPE .CALCULATED ,
72+ "params" : "avg(pgsql.autovacuum.utilization[], 30m)" ,
73+ "delay" : self .plugin_config ("interval" )
74+ }))
75+ return result
2776 else :
2877 return []
2978
3079 def graphs (self , template , dashboard = False ):
3180 result = template .graph ({
3281 "name" : "PostgreSQL Autovacuum: Count of Autovacuum Workers" ,
3382 "items" : [{
34- "key" : self .right_type (self .key ),
83+ "key" : self .right_type (self .key_count ),
3584 "color" : "87C2B9" ,
3685 "drawtype" : 2
3786 }]
@@ -49,9 +98,15 @@ def graphs(self, template, dashboard=False):
4998 def keys_and_queries (self , template_zabbix ):
5099 result = []
51100 if LooseVersion (self .VersionPG ) >= LooseVersion ("10" ):
52- result .append ("{0},$2 $1 -c \" {1}\" " .format (self .key .format ("[*]" ),
101+ result .append ("{0},$2 $1 -c \" {1}\" " .format (self .key_count .format ("[*]" ),
53102 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'" )))
54106 else :
55- result .append ("{0},$2 $1 -c \" {1}\" " .format (self .key .format ("[*]" ),
107+ result .append ("{0},$2 $1 -c \" {1}\" " .format (self .key_count .format ("[*]" ),
56108 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()" )))
57112 return template_zabbix .key_and_query (result )
0 commit comments