fix: add replication metric for native zabbix agent
@@ -6,7 +6,6 @@ from .pool import Pooler
class Xlog(Plugin):
-
DEFAULT_CONFIG = {'lag_more_then_in_sec': str(60 * 5)}
query_wal_lsn_diff = " select pg_catalog.pg_wal_lsn_diff " \
"(pg_catalog.pg_current_wal_lsn(), '0/00000000');"
@@ -14,6 +13,7 @@ class Xlog(Plugin):
"(pg_catalog.pg_current_xlog_location(), '0/00000000');"
key_wall = 'pgsql.wal.write{0}'
key_count_wall = "pgsql.wal.count{0}"
+ key_replication = "pgsql.replication_lag{0}"
AgentPluginType = 'pg'
def run(self, zbx):
@@ -52,7 +52,7 @@ class Xlog(Plugin):
'delta': delta
}) + template.item({
'name': 'PostgreSQL: streaming replication lag',
- 'key': 'pgsql.replication_lag[sec]',
+ 'key': self.right_type(self.key_replication, "sec"),
'delay': self.plugin_config('interval')
}) + template.item({
'name': 'PostgreSQL: count of xlog files',
@@ -71,7 +71,7 @@ class Xlog(Plugin):
'name': 'PostgreSQL replication lag in second',
'items': [
{'color': 'CC0000',
- 'key': 'pgsql.replication_lag[sec]'}]})
+ 'key': self.right_type(self.key_replication, "sec")}]})
result += template.graph({
'name': 'PostgreSQL count of xlog files',
'items': [
@@ -83,18 +83,21 @@ class Xlog(Plugin):
return template.trigger({
'name': 'PostgreSQL streaming lag to high '
'on {HOSTNAME} (value={ITEM.LASTVALUE})',
- 'expression': '{#TEMPLATE:pgsql.replication_lag[sec].last'
- '()}&gt;' + self.plugin_config('lag_more_then_in_sec')
+ 'expression': '{#TEMPLATE:' + self.right_type(self.key_replication, "sec") + '.last()}&gt;' +
+ self.plugin_config('lag_more_then_in_sec')
})
def keys_and_queries(self, template_zabbix):
result = []
if self.VersionPG['number'] < LooseVersion('10'):
- result.append('{0},$2 $1 -c "{1}"'.format(self.key_count_wall.format('[*]'), Pooler.SQL['count_xlog_files'][0]))
+ result.append(
+ '{0},$2 $1 -c "{1}"'.format(self.key_count_wall.format('[*]'), Pooler.SQL['count_xlog_files'][0]))
result.append('{0},$2 $1 -c "{1}"'.format(self.key_wall.format('[*]'), self.query_xlog_lsn_diff))
else:
- result.append('{0},$2 $1 -c "{1}"'.format(self.key_count_wall.format('[*]'), Pooler.SQL['count_wal_files'][0]))
+ result.append(
+ '{0},$2 $1 -c "{1}"'.format(self.key_count_wall.format('[*]'), Pooler.SQL['count_wal_files'][0]))
result.append('{0},$2 $1 -c "{1}"'.format(self.key_wall.format('[*]'), self.query_wal_lsn_diff))
# FIXME for lag
+ result.append(
+ '{0},$2 $1 -c "{1}"'.format("pgsql.replication_lag.sec[*]", Pooler.SQL['replication_lag_slave_query']))
return template_zabbix.key_and_query(result)
-
