7
7
class Autovacuum (Plugin ):
8
8
9
9
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
+ }
11
20
12
21
def run (self , zbx ):
13
22
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'" ])
15
25
else :
16
- result = Pooler .run_sql_type ("count_autovacuum" , args = [
26
+ result_count = Pooler .run_sql_type ("count_autovacuum" , args = [
17
27
"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
+
20
33
def items (self , template , dashboard = False ):
34
+ result = ""
21
35
if not dashboard :
22
- return template .item ({
36
+ result += ( template .item ({
23
37
"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 ,
25
46
"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
27
76
else :
28
77
return []
29
78
30
79
def graphs (self , template , dashboard = False ):
31
80
result = template .graph ({
32
81
"name" : "PostgreSQL Autovacuum: Count of Autovacuum Workers" ,
33
82
"items" : [{
34
- "key" : self .right_type (self .key ),
83
+ "key" : self .right_type (self .key_count ),
35
84
"color" : "87C2B9" ,
36
85
"drawtype" : 2
37
86
}]
@@ -49,9 +98,15 @@ def graphs(self, template, dashboard=False):
49
98
def keys_and_queries (self , template_zabbix ):
50
99
result = []
51
100
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 ("[*]" ),
53
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'" )))
54
106
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 ("[*]" ),
56
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()" )))
57
112
return template_zabbix .key_and_query (result )
0 commit comments