44from mamonsu .plugins .pgsql .plugin import PgsqlPlugin as Plugin
55from .pool import Pooler
66from mamonsu .lib .zbx_template import ZbxTemplate
7+ from mamonsu .plugins .pgsql .autovacuum import Autovacuum
78
89
910class Databases (Plugin ):
@@ -50,7 +51,6 @@ class Databases(Plugin):
5051 key_db_size = "pgsql.database.size{0}"
5152 key_db_age = "pgsql.database.max_age{0}"
5253 key_db_bloating_tables = "pgsql.database.bloating_tables{0}"
53- key_autovacumm = "pgsql.autovacumm.count{0}"
5454 key_invalid_indexes = "pgsql.database.invalid_indexes{0}"
5555
5656 DEFAULT_CONFIG = {
@@ -81,42 +81,6 @@ def run(self, zbx):
8181 zbx .send ("pgsql.database.discovery[]" , zbx .json ({"data" : dbs }))
8282 del dbs , bloat_count , invalid_indexes_count
8383
84- if Pooler .server_version_greater ("10.0" ):
85- result = Pooler .run_sql_type ("count_autovacuum" , args = ["backend_type = 'autovacuum worker'" ])
86- else :
87- result = Pooler .run_sql_type ("count_autovacuum" , args = [
88- "query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()" ])
89- zbx .send ("pgsql.autovacumm.count[]" , int (result [0 ][0 ]))
90-
91- def items (self , template , dashboard = False ):
92- if not dashboard :
93- return template .item ({
94- "name" : "PostgreSQL Autovacuum: Count of Autovacuum Workers" ,
95- "key" : self .right_type (self .key_autovacumm ),
96- "delay" : self .plugin_config ("interval" )
97- })
98- else :
99- return []
100-
101- def graphs (self , template , dashboard = False ):
102- result = template .graph ({
103- "name" : "PostgreSQL Autovacuum: Count of Autovacuum Workers" ,
104- "items" : [{
105- "key" : self .right_type (self .key_autovacumm ),
106- "color" : "87C2B9" ,
107- "drawtype" : 2
108- }]
109- })
110- if not dashboard :
111- return result
112- else :
113- return [{
114- "dashboard" : {"name" : "PostgreSQL Autovacuum: Count of Autovacuum Workers" ,
115- "page" : ZbxTemplate .dashboard_page_overview ["name" ],
116- "size" : ZbxTemplate .dashboard_widget_size_medium ,
117- "position" : 5 }
118- }]
119-
12084 def discovery_rules (self , template , dashboard = False ):
12185 rule = {
12286 "name" : "PostgreSQL Databases Discovery" ,
@@ -166,7 +130,7 @@ def discovery_rules(self, template, dashboard=False):
166130 "key" : self .right_type (self .key_db_bloating_tables , var_discovery = "{#DATABASE}," ),
167131 "drawtype" : 2 },
168132 {"color" : "793F5D" ,
169- "key" : self .right_type (self . key_autovacumm ),
133+ "key" : self .right_type (Autovacuum . key_count ),
170134 "yaxisside" : 1 ,
171135 "drawtype" : 2 }]
172136 },
@@ -177,7 +141,7 @@ def discovery_rules(self, template, dashboard=False):
177141 "key" : self .right_type (self .key_db_age , var_discovery = "{#DATABASE}," ),
178142 "drawtype" : 2 },
179143 {"color" : "793F5D" ,
180- "key" : self .right_type (self . key_autovacumm ),
144+ "key" : self .right_type (Autovacuum . key_count ),
181145 "yaxisside" : 1 ,
182146 "drawtype" : 2 }]
183147 }]
@@ -197,12 +161,4 @@ def keys_and_queries(self, template_zabbix):
197161 self .plugin_config ("min_rows" ))),
198162 "{0},$3 $2 -d \" $1\" -c \" {1}\" " .format (self .key_invalid_indexes .format ("[*]" ),
199163 self .query_invalid_indexes )]
200- if LooseVersion (self .VersionPG ) >= LooseVersion ("10" ):
201- result .append ("{0},$2 $1 -c \" {1}\" " .format (self .key_autovacumm .format ("[*]" ),
202- Pooler .SQL ["count_autovacuum" ][0 ].format (
203- "backend_type = 'autovacuum worker'" )))
204- else :
205- result .append ("{0},$2 $1 -c \" {1}\" " .format (self .key_autovacumm .format ("[*]" ),
206- Pooler .SQL ["count_autovacuum" ][0 ].format (
207- "query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()" )))
208164 return template_zabbix .key_and_query (result )
0 commit comments