11# -*- coding: utf-8 -*-
2- from distutils .version import LooseVersion
32from mamonsu .plugins .pgsql .plugin import PgsqlPlugin as Plugin
43from .pool import Pooler
54from mamonsu .lib .zbx_template import ZbxTemplate
65
6+
77class Autovacuum (Plugin ):
8-
98 AgentPluginType = "pg"
109 # TODO: unify keys and remove its direct mentioning in zbx.send() functions
1110 key_count = "pgsql.autovacuum.count{0}"
@@ -21,7 +20,8 @@ class Autovacuum(Plugin):
2120 def run (self , zbx ):
2221 if Pooler .server_version_greater ("10.0" ):
2322 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'" ])
23+ result_utilization = Pooler .run_sql_type ("autovacuum_utilization" ,
24+ args = ["backend_type = 'autovacuum worker'" ])
2525 else :
2626 result_count = Pooler .run_sql_type ("count_autovacuum" , args = [
2727 "query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()" ])
@@ -51,7 +51,7 @@ def items(self, template, dashboard=False):
5151 "value_type" : Plugin .VALUE_TYPE .numeric_float ,
5252 "units" : Plugin .UNITS .percent ,
5353 "type" : Plugin .TYPE .CALCULATED ,
54- "params" : "avg(pgsql.autovacuum.utilization[] , 5m)" ,
54+ "params" : "avg(//{item} , 5m)" . format ( item = self . right_type ( self . key_utilization )) ,
5555 "delay" : self .plugin_config ("interval" )
5656 }))
5757 result += (template .item ({
@@ -60,7 +60,7 @@ def items(self, template, dashboard=False):
6060 "value_type" : Plugin .VALUE_TYPE .numeric_float ,
6161 "units" : Plugin .UNITS .percent ,
6262 "type" : Plugin .TYPE .CALCULATED ,
63- "params" : "avg(pgsql.autovacuum.utilization[] , 15m)" ,
63+ "params" : "avg(//{item} , 15m)" . format ( item = self . right_type ( self . key_utilization )) ,
6464 "delay" : self .plugin_config ("interval" )
6565 }))
6666 result += (template .item ({
@@ -69,13 +69,13 @@ def items(self, template, dashboard=False):
6969 "value_type" : Plugin .VALUE_TYPE .numeric_float ,
7070 "units" : Plugin .UNITS .percent ,
7171 "type" : Plugin .TYPE .CALCULATED ,
72- "params" : "avg(pgsql.autovacuum.utilization[] , 30m)" ,
72+ "params" : "avg(//{item} , 30m)" . format ( item = self . right_type ( self . key_utilization )) ,
7373 "delay" : self .plugin_config ("interval" )
7474 }))
7575 return result
7676 else :
7777 return []
78-
78+
7979 def graphs (self , template , dashboard = False ):
8080 result = template .graph ({
8181 "name" : "PostgreSQL Autovacuum: Count of Autovacuum Workers" ,
@@ -97,16 +97,20 @@ def graphs(self, template, dashboard=False):
9797
9898 def keys_and_queries (self , template_zabbix ):
9999 result = []
100- 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'" )))
100+ if Pooler .server_version_greater ("10" ):
101+ # TODO: define another metric key because it duplicates native zabbix agents keys
102+ # result.append("{0},$2 $1 -c \"{1}\"".format(self.key_count.format("[*]"),
103+ # Pooler.SQL["count_autovacuum"][0].format(
104+ # "backend_type = 'autovacuum worker'")))
103105 result .append ("{0},$2 $1 -c \" {1}\" " .format (self .key_utilization .format ("[*]" ),
104- Pooler .SQL ["autovacuum_utilization" ][0 ].format (
105- "backend_type = 'autovacuum worker'" )))
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+ # TODO: define another metric key because it duplicates native zabbix agents keys
110+ # result.append("{0},$2 $1 -c \"{1}\"".format(self.key_count.format("[*]"),
111+ # Pooler.SQL["count_autovacuum"][0].format(
112+ # "query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()")))
109113 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()" )))
114+ Pooler .SQL ["autovacuum_utilization" ][0 ].format (
115+ "query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()" )))
112116 return template_zabbix .key_and_query (result )
0 commit comments