Skip to content

Commit df1ceeb

Browse files
committed
fix: fixed native zabbix agent metrics format
1 parent da87b8f commit df1ceeb

File tree

14 files changed

+158
-134
lines changed

14 files changed

+158
-134
lines changed

mamonsu/plugins/pgsql/archive_command.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ class ArchiveCommand(Plugin):
5959
key = "pgsql.archive_command{0}"
6060
Items = [
6161
# key, desc, color, side, graph, delta, units
62-
("count_files_to_archive", "Files in archive_status Need to Archive Count", "006AAE", 0, 1, Plugin.DELTA.as_is, Plugin.UNITS.none),
62+
("count_files_to_archive", "Files in archive_status Need to Archive Count", "006AAE", 0, 1, Plugin.DELTA.as_is,
63+
Plugin.UNITS.none),
6364
("size_files_to_archive", "Files Need to Archive Size", "793F5D", 0, 0, Plugin.DELTA.as_is, Plugin.UNITS.bytes),
6465
("archived_files", "Archived Files Count", "00CC00", 0, 1, Plugin.DELTA.simple_change, Plugin.UNITS.none),
65-
("failed_trying_to_archive", "Attempts to Archive Files Count", "FF5656", 0, 1, Plugin.DELTA.simple_change, Plugin.UNITS.none),
66+
("failed_trying_to_archive", "Attempts to Archive Files Count", "FF5656", 0, 1, Plugin.DELTA.simple_change,
67+
Plugin.UNITS.none),
6668
]
6769
old_archived_count = None
6870
old_failed_count = None
@@ -192,25 +194,27 @@ def triggers(self, template, dashboard=False):
192194
return template.trigger({
193195
"name": "PostgreSQL Archiver: count files need to archive on {HOSTNAME} more than 2",
194196
"expression": "{#TEMPLATE:" + self.right_type(self.key,
195-
self.Items[0][0]) + ".last()}>" + self.plugin_macros["archive_queue_files"][0][1]
197+
self.Items[0][0]) + ".last()}>" +
198+
self.plugin_macros["archive_queue_files"][0][1]
196199
})
197200

198201
def keys_and_queries(self, template_zabbix):
199202
result = []
200203
if LooseVersion(self.VersionPG) >= LooseVersion("10"):
201-
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + self.Items[0][0]),
202-
self.query_agent_count_files.format("wal_lsn", "walfile")))
203-
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + self.Items[1][0]),
204-
self.query_agent_size_files.format("wal_lsn", "walfile")))
204+
result.append("{0}[*],$2 $1 -Aqtc \"{1}\"".format(self.key.format("." + self.Items[0][0]),
205+
self.query_agent_count_files.format("wal_lsn",
206+
"walfile")))
207+
result.append("{0}[*],$2 $1 -Aqtc \"{1}\"".format(self.key.format("." + self.Items[1][0]),
208+
self.query_agent_size_files.format("wal_lsn", "walfile")))
205209
else:
206-
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + self.Items[0][0]),
207-
self.query_agent_count_files.format("xlog_location",
208-
"xlogfile")))
209-
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + self.Items[1][0]),
210-
self.query_agent_size_files.format("xlog_location",
211-
"xlogfile")))
212-
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + self.Items[2][0]),
213-
self.query_agent_archived_count))
214-
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + self.Items[3][0]),
215-
self.query_agent_failed_count))
210+
result.append("{0}[*],$2 $1 -Aqtc \"{1}\"".format(self.key.format("." + self.Items[0][0]),
211+
self.query_agent_count_files.format("xlog_location",
212+
"xlogfile")))
213+
result.append("{0}[*],$2 $1 -Aqtc \"{1}\"".format(self.key.format("." + self.Items[1][0]),
214+
self.query_agent_size_files.format("xlog_location",
215+
"xlogfile")))
216+
result.append("{0}[*],$2 $1 -Aqtc \"{1}\"".format(self.key.format("." + self.Items[2][0]),
217+
self.query_agent_archived_count))
218+
result.append("{0}[*],$2 $1 -Aqtc \"{1}\"".format(self.key.format("." + self.Items[3][0]),
219+
self.query_agent_failed_count))
216220
return template_zabbix.key_and_query(result)

mamonsu/plugins/pgsql/autovacuum.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from .pool import Pooler
55
from mamonsu.lib.zbx_template import ZbxTemplate
66

7+
78
class Autovacuum(Plugin):
8-
99
AgentPluginType = "pg"
1010
# TODO: unify keys and remove its direct mentioning in zbx.send() functions
1111
key_count = "pgsql.autovacuum.count{0}"
@@ -21,7 +21,8 @@ class Autovacuum(Plugin):
2121
def run(self, zbx):
2222
if Pooler.server_version_greater("10.0"):
2323
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'"])
24+
result_utilization = Pooler.run_sql_type("autovacuum_utilization",
25+
args=["backend_type = 'autovacuum worker'"])
2526
else:
2627
result_count = Pooler.run_sql_type("count_autovacuum", args=[
2728
"query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()"])
@@ -51,7 +52,7 @@ def items(self, template, dashboard=False):
5152
"value_type": Plugin.VALUE_TYPE.numeric_float,
5253
"units": Plugin.UNITS.percent,
5354
"type": Plugin.TYPE.CALCULATED,
54-
"params": "avg(pgsql.autovacuum.utilization[], 5m)",
55+
"params": "avg({item}, 5m)".format(item=self.key_utilization.format("[]")),
5556
"delay": self.plugin_config("interval")
5657
}))
5758
result += (template.item({
@@ -60,7 +61,7 @@ def items(self, template, dashboard=False):
6061
"value_type": Plugin.VALUE_TYPE.numeric_float,
6162
"units": Plugin.UNITS.percent,
6263
"type": Plugin.TYPE.CALCULATED,
63-
"params": "avg(pgsql.autovacuum.utilization[], 15m)",
64+
"params": "avg({item}, 15m)".format(item=self.key_utilization.format("[]")),
6465
"delay": self.plugin_config("interval")
6566
}))
6667
result += (template.item({
@@ -69,13 +70,13 @@ def items(self, template, dashboard=False):
6970
"value_type": Plugin.VALUE_TYPE.numeric_float,
7071
"units": Plugin.UNITS.percent,
7172
"type": Plugin.TYPE.CALCULATED,
72-
"params": "avg(pgsql.autovacuum.utilization[], 30m)",
73+
"params": "avg({item}, 30m)".format(item=self.key_utilization.format("[]")),
7374
"delay": self.plugin_config("interval")
7475
}))
7576
return result
7677
else:
7778
return []
78-
79+
7980
def graphs(self, template, dashboard=False):
8081
result = template.graph({
8182
"name": "PostgreSQL Autovacuum: Count of Autovacuum Workers",
@@ -98,15 +99,17 @@ def graphs(self, template, dashboard=False):
9899
def keys_and_queries(self, template_zabbix):
99100
result = []
100101
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'")))
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'")))
102+
result.append("{0},$2 $1 -Aqtc \"{1}\"".format(self.key_count.format("[*]"),
103+
Pooler.SQL["count_autovacuum"][0].format(
104+
"backend_type = 'autovacuum worker'")))
105+
result.append("{0},$2 $1 -Aqtc \"{1}\"".format(self.key_utilization.format("[*]"),
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-
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()")))
109+
result.append("{0},$2 $1 -Aqtc \"{1}\"".format(self.key_count.format("[*]"),
110+
Pooler.SQL["count_autovacuum"][0].format(
111+
"query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()")))
112+
result.append("{0},$2 $1 -Aqtc \"{1}\"".format(self.key_utilization.format("[*]"),
113+
Pooler.SQL["autovacuum_utilization"][0].format(
114+
"query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()")))
112115
return template_zabbix.key_and_query(result)

mamonsu/plugins/pgsql/bgwriter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,6 @@ def keys_and_queries(self, template_zabbix):
119119
result = []
120120
for item in self.Items:
121121
# delete from key '[' and ']' in Item for zabbix agent
122-
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + item[0]), self.query.format(item[0])))
122+
result.append(
123+
"{0}[*],$2 $1 -Aqtc \"{1}\"".format(self.key.format("." + item[0]), self.query.format(item[0])))
123124
return template_zabbix.key_and_query(result)

mamonsu/plugins/pgsql/checkpoint.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def graphs(self, template, dashboard=False):
101101
"name": self.graph_name_count,
102102
"items": items_checkpoints
103103
}) + template.graph({
104-
"name": self.graph_name_ws,
105-
"items": items_checkpoints_write_sync
104+
"name": self.graph_name_ws,
105+
"items": items_checkpoints_write_sync
106106
})
107107
if not dashboard:
108108
return result
@@ -133,17 +133,18 @@ def triggers(self, template, dashboard=False):
133133
return template.trigger({
134134
"name": "PostgreSQL Checkpoints: required checkpoints occurs too frequently on {HOSTNAME}",
135135
"expression": "{#TEMPLATE:" + self.right_type(self.key,
136-
self.Items[1][1]) + ".last()}&gt;" + self.plugin_macros["max_checkpoint_by_wal_in_hour"][0][1]
136+
self.Items[1][1]) + ".last()}&gt;" +
137+
self.plugin_macros["max_checkpoint_by_wal_in_hour"][0][1]
137138
})
138139

139140
def keys_and_queries(self, template_zabbix):
140141
result = []
141142
for num, item in enumerate(self.Items):
142143
if num > 1:
143144
result.append(
144-
"{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + item[1]), self.query.format(item[0])))
145+
"{0}[*],$2 $1 -Aqtc \"{1}\"".format(self.key.format("." + item[1]), self.query.format(item[0])))
145146
else:
146147
result.append(
147-
"{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + item[1]),
148-
self.query_interval.format(item[0])))
148+
"{0}[*],$2 $1 -Aqtc \"{1}\"".format(self.key.format("." + item[1]),
149+
self.query_interval.format(item[0])))
149150
return template_zabbix.key_and_query(result)

mamonsu/plugins/pgsql/connections.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -239,30 +239,31 @@ def triggers(self, template, dashboard=False):
239239
def keys_and_queries(self, template_zabbix):
240240
result = []
241241
for item in self.Items:
242-
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + item[1]),
243-
self.query_agent.format(item[1],
244-
"AND (backend_type = 'client backend' OR backend_type = 'parallel worker')" if LooseVersion(
245-
self.VersionPG) >= LooseVersion(
246-
"10") else "")))
247-
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format(".total"), self.query_agent_total.format(
242+
result.append("{0}[*],$2 $1 -Aqtc \"{1}\"".format(self.key.format("." + item[1]),
243+
self.query_agent.format(item[1],
244+
"AND (backend_type = 'client backend' OR backend_type = 'parallel worker')" if LooseVersion(
245+
self.VersionPG) >= LooseVersion(
246+
"10") else "")))
247+
result.append("{0}[*],$2 $1 -Aqtc \"{1}\"".format(self.key.format(".total"), self.query_agent_total.format(
248248
"(backend_type = 'client backend' OR backend_type = 'parallel worker')" if LooseVersion(
249249
self.VersionPG) >= LooseVersion(
250250
"10") else "state IS NOT NULL")))
251251
if LooseVersion(self.VersionPG) < LooseVersion("9.6"):
252252
result.append(
253-
"{0}[*],$2 $1 -c \"{1}\"".format(self.key.format(".waiting"), self.query_agent_waiting_old_v.format(
253+
"{0}[*],$2 $1 -Aqtc \"{1}\"".format(self.key.format(".waiting"), self.query_agent_waiting_old_v.format(
254254
"(backend_type = 'client backend' OR backend_type = 'parallel worker')" if LooseVersion(
255255
self.VersionPG) >= LooseVersion(
256256
"10") else "state IS NOT NULL")))
257257
else:
258258
result.append(
259-
"{0}[*],$2 $1 -c \"{1}\"".format(self.key.format(".waiting"), self.query_agent_waiting_new_v.format(
259+
"{0}[*],$2 $1 -Aqtc \"{1}\"".format(self.key.format(".waiting"), self.query_agent_waiting_new_v.format(
260260
"(backend_type = 'client backend' OR backend_type = 'parallel worker')" if LooseVersion(
261261
self.VersionPG) >= LooseVersion(
262262
"10") else "state IS NOT NULL")))
263263
if LooseVersion(self.VersionPG) >= LooseVersion("10"):
264-
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format(".other"),
265-
self.query_other_connections.format(
266-
"', '".join(self.default_backend_types))))
267-
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format(".max_connections"), self.query_agent_max_conn))
264+
result.append("{0}[*],$2 $1 -Aqtc \"{1}\"".format(self.key.format(".other"),
265+
self.query_other_connections.format(
266+
"', '".join(self.default_backend_types))))
267+
result.append(
268+
"{0}[*],$2 $1 -Aqtc \"{1}\"".format(self.key.format(".max_connections"), self.query_agent_max_conn))
268269
return template_zabbix.key_and_query(result)

mamonsu/plugins/pgsql/databases.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ def discovery_rules(self, template, dashboard=False):
152152
return template.discovery_rule(rule=rule, conditions=conditions, items=items, graphs=graphs, triggers=triggers)
153153

154154
def keys_and_queries(self, template_zabbix):
155-
result = ["{0},$2 $1 -c \"{1}\"".format(self.key_db_discovery.format("[*]"), self.query_agent_discovery),
155+
result = ["{0},$2 $1 -Aqtc \"{1}\"".format(self.key_db_discovery.format("[*]"), self.query_agent_discovery),
156156
"{0},echo \"{1}\" | $3 $2 -v p1=\"$1\"".format(self.key_db_size.format("[*]"), self.query_size),
157157
"{0},echo \"{1}\" | $3 $2 -v p1=\"$1\"".format(self.key_db_age.format("[*]"), self.query_age),
158-
"{0},$3 $2 -d \"$1\" -c \"{1}\"".format(self.key_db_bloating_tables.format("[*]"),
159-
self.query_bloating_tables.format(
160-
self.plugin_config("bloat_scale"),
161-
self.plugin_config("min_rows"))),
162-
"{0},$3 $2 -d \"$1\" -c \"{1}\"".format(self.key_invalid_indexes.format("[*]"),
163-
self.query_invalid_indexes)]
158+
"{0},$3 $2 -d \"$1\" -Aqtc \"{1}\"".format(self.key_db_bloating_tables.format("[*]"),
159+
self.query_bloating_tables.format(
160+
self.plugin_config("bloat_scale"),
161+
self.plugin_config("min_rows"))),
162+
"{0},$3 $2 -d \"$1\" -Aqtc \"{1}\"".format(self.key_invalid_indexes.format("[*]"),
163+
self.query_invalid_indexes)]
164164
return template_zabbix.key_and_query(result)

0 commit comments

Comments
 (0)