Skip to content

Commit 59af746

Browse files
committed
feature: created detached Autovacuum plugin
1 parent 4f33aed commit 59af746

File tree

6 files changed

+69
-263
lines changed

6 files changed

+69
-263
lines changed

github-actions-tests/sources/agent_3.4.0.conf

Lines changed: 0 additions & 216 deletions
This file was deleted.

github-actions-tests/sources/agent_3.5.0.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ interval = 15
8484
[bgwriter]
8585
interval = 15
8686

87+
[autovacuum]
88+
interval = 60
89+
8790
[connections]
8891
percent_connections_tr = 90
8992
interval = 15

mamonsu/plugins/pgsql/autovacuum.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# -*- coding: utf-8 -*-
2+
from distutils.version import LooseVersion
3+
from mamonsu.plugins.pgsql.plugin import PgsqlPlugin as Plugin
4+
from .pool import Pooler
5+
from mamonsu.lib.zbx_template import ZbxTemplate
6+
7+
class Autovacuum(Plugin):
8+
9+
AgentPluginType = "pg"
10+
key = "pgsql.autovacuum.count{0}"
11+
12+
def run(self, zbx):
13+
if Pooler.server_version_greater("10.0"):
14+
result = Pooler.run_sql_type("count_autovacuum", args=["backend_type = 'autovacuum worker'"])
15+
else:
16+
result = Pooler.run_sql_type("count_autovacuum", args=[
17+
"query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()"])
18+
zbx.send("pgsql.autovacuum.count[]", int(result[0][0]))
19+
20+
def items(self, template, dashboard=False):
21+
if not dashboard:
22+
return template.item({
23+
"name": "PostgreSQL Autovacuum: Count of Autovacuum Workers",
24+
"key": self.right_type(self.key),
25+
"delay": self.plugin_config("interval")
26+
})
27+
else:
28+
return []
29+
30+
def graphs(self, template, dashboard=False):
31+
result = template.graph({
32+
"name": "PostgreSQL Autovacuum: Count of Autovacuum Workers",
33+
"items": [{
34+
"key": self.right_type(self.key),
35+
"color": "87C2B9",
36+
"drawtype": 2
37+
}]
38+
})
39+
if not dashboard:
40+
return result
41+
else:
42+
return [{
43+
"dashboard": {"name": "PostgreSQL Autovacuum: Count of Autovacuum Workers",
44+
"page": ZbxTemplate.dashboard_page_overview["name"],
45+
"size": ZbxTemplate.dashboard_widget_size_medium,
46+
"position": 5}
47+
}]
48+
49+
def keys_and_queries(self, template_zabbix):
50+
result = []
51+
if LooseVersion(self.VersionPG) >= LooseVersion("10"):
52+
result.append("{0},$2 $1 -c \"{1}\"".format(self.key.format("[*]"),
53+
Pooler.SQL["count_autovacuum"][0].format("backend_type = 'autovacuum worker'")))
54+
else:
55+
result.append("{0},$2 $1 -c \"{1}\"".format(self.key.format("[*]"),
56+
Pooler.SQL["count_autovacuum"][0].format("query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()")))
57+
return template_zabbix.key_and_query(result)

mamonsu/plugins/pgsql/databases.py

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from mamonsu.plugins.pgsql.plugin import PgsqlPlugin as Plugin
55
from .pool import Pooler
66
from mamonsu.lib.zbx_template import ZbxTemplate
7+
from mamonsu.plugins.pgsql.autovacuum import Autovacuum
78

89

910
class 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),
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),
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)

packaging/conf/example_linux.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ interval = 60
8585
max_count_files = 2
8686
interval = 60
8787

88+
[autovacuum]
89+
interval = 60
90+
8891
[bgwriter]
8992
interval = 60
9093

packaging/conf/example_win.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ interval = 60
8585
max_count_files = 2
8686
interval = 60
8787

88+
[autovacuum]
89+
interval = 60
90+
8891
[bgwriter]
8992
interval = 60
9093

0 commit comments

Comments
 (0)