Skip to content

Commit da2bba0

Browse files
committed
fix: add replication metric for native zabbix agent
1 parent 9921492 commit da2bba0

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

mamonsu/plugins/pgsql/xlog.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77

88
class Xlog(Plugin):
9-
109
DEFAULT_CONFIG = {'lag_more_then_in_sec': str(60 * 5)}
1110
query_wal_lsn_diff = " select pg_catalog.pg_wal_lsn_diff " \
1211
"(pg_catalog.pg_current_wal_lsn(), '0/00000000');"
1312
query_xlog_lsn_diff = "select pg_catalog.pg_xlog_location_diff " \
14-
"(pg_catalog.pg_current_xlog_location(), '0/00000000');"
13+
"(pg_catalog.pg_current_xlog_location(), '0/00000000');"
1514
key_wall = 'pgsql.wal.write{0}'
1615
key_count_wall = "pgsql.wal.count{0}"
16+
key_replication = "pgsql.replication_lag{0}"
1717
AgentPluginType = 'pg'
1818

1919
def run(self, zbx):
@@ -45,56 +45,59 @@ def items(self, template):
4545
else:
4646
delta = Plugin.DELTA_SPEED
4747
result += template.item({
48-
'name': 'PostgreSQL: wal write speed',
49-
'key': self.right_type(self.key_wall),
50-
'units': Plugin.UNITS.bytes,
51-
'delay': self.plugin_config('interval'),
52-
'delta': delta
53-
}) + template.item({
54-
'name': 'PostgreSQL: streaming replication lag',
55-
'key': 'pgsql.replication_lag[sec]',
56-
'delay': self.plugin_config('interval')
57-
}) + template.item({
58-
'name': 'PostgreSQL: count of xlog files',
59-
'key': self.right_type(self.key_count_wall),
60-
'delay': self.plugin_config('interval')
61-
})
48+
'name': 'PostgreSQL: wal write speed',
49+
'key': self.right_type(self.key_wall),
50+
'units': Plugin.UNITS.bytes,
51+
'delay': self.plugin_config('interval'),
52+
'delta': delta
53+
}) + template.item({
54+
'name': 'PostgreSQL: streaming replication lag',
55+
'key': self.right_type(self.key_replication, "sec"),
56+
'delay': self.plugin_config('interval')
57+
}) + template.item({
58+
'name': 'PostgreSQL: count of xlog files',
59+
'key': self.right_type(self.key_count_wall),
60+
'delay': self.plugin_config('interval')
61+
})
6262
return result
6363

6464
def graphs(self, template):
6565
result = template.graph({
6666
'name': 'PostgreSQL write-ahead log generation speed',
6767
'items': [
6868
{'color': 'CC0000',
69-
'key': self.right_type(self.key_wall)}]})
69+
'key': self.right_type(self.key_wall)}]})
7070
result += template.graph({
7171
'name': 'PostgreSQL replication lag in second',
7272
'items': [
7373
{'color': 'CC0000',
74-
'key': 'pgsql.replication_lag[sec]'}]})
74+
'key': self.right_type(self.key_replication, "sec")}]})
7575
result += template.graph({
7676
'name': 'PostgreSQL count of xlog files',
7777
'items': [
7878
{'color': 'CC0000',
79-
'key': self.right_type(self.key_count_wall)}]})
79+
'key': self.right_type(self.key_count_wall)}]})
8080
return result
8181

8282
def triggers(self, template):
8383
return template.trigger({
8484
'name': 'PostgreSQL streaming lag to high '
85-
'on {HOSTNAME} (value={ITEM.LASTVALUE})',
86-
'expression': '{#TEMPLATE:pgsql.replication_lag[sec].last'
87-
'()}>' + self.plugin_config('lag_more_then_in_sec')
85+
'on {HOSTNAME} (value={ITEM.LASTVALUE})',
86+
'expression': '{#TEMPLATE:' + self.right_type(self.key_replication, "sec") + '.last()}>' +
87+
self.plugin_config('lag_more_then_in_sec')
8888
})
8989

9090
def keys_and_queries(self, template_zabbix):
9191
result = []
9292
if self.VersionPG['number'] < LooseVersion('10'):
93-
result.append('{0},$2 $1 -c "{1}"'.format(self.key_count_wall.format('[*]'), Pooler.SQL['count_xlog_files'][0]))
93+
result.append(
94+
'{0},$2 $1 -c "{1}"'.format(self.key_count_wall.format('[*]'), Pooler.SQL['count_xlog_files'][0]))
9495
result.append('{0},$2 $1 -c "{1}"'.format(self.key_wall.format('[*]'), self.query_xlog_lsn_diff))
9596
else:
96-
result.append('{0},$2 $1 -c "{1}"'.format(self.key_count_wall.format('[*]'), Pooler.SQL['count_wal_files'][0]))
97+
result.append(
98+
'{0},$2 $1 -c "{1}"'.format(self.key_count_wall.format('[*]'), Pooler.SQL['count_wal_files'][0]))
9799
result.append('{0},$2 $1 -c "{1}"'.format(self.key_wall.format('[*]'), self.query_wal_lsn_diff))
98100
# FIXME for lag
101+
result.append(
102+
'{0},$2 $1 -c "{1}"'.format("pgsql.replication_lag.sec[*]", Pooler.SQL['replication_lag_slave_query']))
99103
return template_zabbix.key_and_query(result)
100-

0 commit comments

Comments
 (0)