4
4
from mamonsu .plugins .pgsql .plugin import PgsqlPlugin as Plugin
5
5
from .pool import Pooler
6
6
from mamonsu .lib .zbx_template import ZbxTemplate
7
+ from mamonsu .plugins .pgsql .autovacuum import Autovacuum
7
8
8
9
9
10
class Databases (Plugin ):
@@ -50,7 +51,6 @@ class Databases(Plugin):
50
51
key_db_size = "pgsql.database.size{0}"
51
52
key_db_age = "pgsql.database.max_age{0}"
52
53
key_db_bloating_tables = "pgsql.database.bloating_tables{0}"
53
- key_autovacumm = "pgsql.autovacumm.count{0}"
54
54
key_invalid_indexes = "pgsql.database.invalid_indexes{0}"
55
55
56
56
DEFAULT_CONFIG = {
@@ -81,42 +81,6 @@ def run(self, zbx):
81
81
zbx .send ("pgsql.database.discovery[]" , zbx .json ({"data" : dbs }))
82
82
del dbs , bloat_count , invalid_indexes_count
83
83
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
-
120
84
def discovery_rules (self , template , dashboard = False ):
121
85
rule = {
122
86
"name" : "PostgreSQL Databases Discovery" ,
@@ -166,7 +130,7 @@ def discovery_rules(self, template, dashboard=False):
166
130
"key" : self .right_type (self .key_db_bloating_tables , var_discovery = "{#DATABASE}," ),
167
131
"drawtype" : 2 },
168
132
{"color" : "793F5D" ,
169
- "key" : self .right_type (self . key_autovacumm ),
133
+ "key" : self .right_type (Autovacuum . key_count ),
170
134
"yaxisside" : 1 ,
171
135
"drawtype" : 2 }]
172
136
},
@@ -177,7 +141,7 @@ def discovery_rules(self, template, dashboard=False):
177
141
"key" : self .right_type (self .key_db_age , var_discovery = "{#DATABASE}," ),
178
142
"drawtype" : 2 },
179
143
{"color" : "793F5D" ,
180
- "key" : self .right_type (self . key_autovacumm ),
144
+ "key" : self .right_type (Autovacuum . key_count ),
181
145
"yaxisside" : 1 ,
182
146
"drawtype" : 2 }]
183
147
}]
@@ -197,12 +161,4 @@ def keys_and_queries(self, template_zabbix):
197
161
self .plugin_config ("min_rows" ))),
198
162
"{0},$3 $2 -d \" $1\" -c \" {1}\" " .format (self .key_invalid_indexes .format ("[*]" ),
199
163
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()" )))
208
164
return template_zabbix .key_and_query (result )
0 commit comments