Skip to content

Commit 07e31ed

Browse files
committed
Merge branch 'dev'
2 parents 7b8c9d5 + e1013ef commit 07e31ed

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

mamonsu/plugins/pgsql/health.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def items(self, template, dashboard=False):
5959
"type": Plugin.TYPE.CALCULATED,
6060
"params": "last(//{blocks_hit})*100/(last(//{blocks_hit})+last(//{blocks_read}))".format(
6161
# TODO: hardcoded params
62-
blocks_hit=self.right_type("pgsql.blocks.hit{0}"),
63-
blocks_read=self.right_type("pgsql.blocks.read{0}"))
62+
blocks_hit=self.right_type("pgsql.blocks{0}", "hit"),
63+
blocks_read=self.right_type("pgsql.blocks{0}", "read"))
6464
}) + template.item({
6565
"name": "PostgreSQL Health: Service Uptime",
6666
"key": self.right_type(self.key_uptime),
@@ -106,19 +106,22 @@ def macros(self, template, dashboard=False):
106106
return []
107107

108108
def triggers(self, template, dashboard=False):
109-
result = template.trigger({
110-
"name": "PostgreSQL Health: service has been restarted on {HOSTNAME} (uptime={ITEM.LASTVALUE})",
111-
"expression": "{#TEMPLATE:" + self.right_type(self.key_uptime) + ".change()}>" +
112-
self.plugin_macros["pg_uptime"][0][1]
113-
}) + template.trigger({
114-
"name": "PostgreSQL Health: cache hit ratio too low on {HOSTNAME} ({ITEM.LASTVALUE})",
115-
"expression": "{#TEMPLATE:" + self.right_type(self.key_cache, "hit") + ".last()}<" +
116-
self.plugin_macros["cache_hit_ratio_percent"][0][1]
117-
}) + template.trigger({
118-
"name": "PostgreSQL Health: no ping from PostgreSQL for 3 minutes on {HOSTNAME}",
119-
"expression": "{#TEMPLATE:" + self.right_type(self.key_ping) + ".nodata(180)}=1"
120-
})
121-
return result
109+
if self.Type == 'mamonsu':
110+
result = template.trigger({
111+
"name": "PostgreSQL Health: service has been restarted on {HOSTNAME} (uptime={ITEM.LASTVALUE})",
112+
"expression": "{#TEMPLATE:" + self.right_type(self.key_uptime) + ".change()}>" +
113+
self.plugin_macros["pg_uptime"][0][1]
114+
}) + template.trigger({
115+
"name": "PostgreSQL Health: cache hit ratio too low on {HOSTNAME} ({ITEM.LASTVALUE})",
116+
"expression": "{#TEMPLATE:" + self.right_type(self.key_cache, "hit") + ".last()}<" +
117+
self.plugin_macros["cache_hit_ratio_percent"][0][1]
118+
}) + template.trigger({
119+
"name": "PostgreSQL Health: no ping from PostgreSQL for 3 minutes on {HOSTNAME}",
120+
"expression": "{#TEMPLATE:" + self.right_type(self.key_ping) + ".nodata(180)}=1"
121+
})
122+
return result
123+
else:
124+
return ""
122125

123126
def keys_and_queries(self, template_zabbix):
124127
# TODO: define another metric key because it duplicates native zabbix agents keys

mamonsu/plugins/pgsql/statements.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,25 +213,26 @@ def keys_and_queries(self, template_zabbix):
213213

214214
for i, item in enumerate(all_items):
215215
keys = item[0].split("[")
216-
result.append("{0}[*],$2 $1 -c \"{1}\"".format("{0}{1}.{2}".format(self.key, keys[0], keys[1][:-1]),
217-
self.query[self.extension + "_bootstrap"].format(
218-
columns=", ".join(
219-
[x[0][x[0].find("[") + 1:x[0].find("]")] for x
220-
in
221-
all_items]), metrics=(", ".join(columns)),
222-
extension_schema=extension_schema) if Pooler.is_bootstraped() else
223-
self.query[self.extension].format(
224-
metrics=(", ".join(columns)),
225-
extension_schema=extension_schema)))
216+
result.append("{0}[*],$2 $1 -c \"{1}\" | awk -F '|' '{{print ${2}}}'".format(
217+
"{0}{1}.{2}".format(self.key, keys[0], keys[1][:-1]),
218+
self.query[self.extension + "_bootstrap"].format(
219+
columns=", ".join([x[0][x[0].find("[") + 1:x[0].find("]")] for x in all_items]),
220+
metrics=(", ".join(columns)),
221+
extension_schema=extension_schema) if Pooler.is_bootstraped() else
222+
self.query[self.extension].format(
223+
metrics=(", ".join(columns)),
224+
extension_schema=extension_schema),
225+
i + 1))
226226

227227
if Pooler.server_version_greater("14"):
228228
if self.extension == "pg_stat_statements":
229229
for i, item in enumerate(self.Items_pg_14):
230230
keys = item[0].split("[")
231231
result.append(
232-
"{0}[*],$2 $1 -c \"{1}\"".format("{0}{1}.{2}".format(self.key, keys[0], keys[1][:-1]),
233-
self.query_info.format(metrics=(item[1]),
234-
extension_schema=extension_schema)))
232+
"{0}[*],$2 $1 -c \"{1}\" | awk -F '|' '{{print ${2}}}'".format(
233+
"{0}{1}.{2}".format(self.key, keys[0], keys[1][:-1]),
234+
self.query_info.format(metrics=(item[1]), extension_schema=extension_schema),
235+
i + 1))
235236
return template_zabbix.key_and_query(result)
236237
else:
237238
return

0 commit comments

Comments
 (0)