|
6 | 6 |
|
7 | 7 |
|
8 | 8 | class Xlog(Plugin):
|
9 |
| - |
10 | 9 | DEFAULT_CONFIG = {'lag_more_then_in_sec': str(60 * 5)}
|
11 | 10 | query_wal_lsn_diff = " select pg_catalog.pg_wal_lsn_diff " \
|
12 | 11 | "(pg_catalog.pg_current_wal_lsn(), '0/00000000');"
|
13 | 12 | 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');" |
15 | 14 | key_wall = 'pgsql.wal.write{0}'
|
16 | 15 | key_count_wall = "pgsql.wal.count{0}"
|
| 16 | + key_replication = "pgsql.replication_lag{0}" |
17 | 17 | AgentPluginType = 'pg'
|
18 | 18 |
|
19 | 19 | def run(self, zbx):
|
@@ -45,56 +45,59 @@ def items(self, template):
|
45 | 45 | else:
|
46 | 46 | delta = Plugin.DELTA_SPEED
|
47 | 47 | 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 | + }) |
62 | 62 | return result
|
63 | 63 |
|
64 | 64 | def graphs(self, template):
|
65 | 65 | result = template.graph({
|
66 | 66 | 'name': 'PostgreSQL write-ahead log generation speed',
|
67 | 67 | 'items': [
|
68 | 68 | {'color': 'CC0000',
|
69 |
| - 'key': self.right_type(self.key_wall)}]}) |
| 69 | + 'key': self.right_type(self.key_wall)}]}) |
70 | 70 | result += template.graph({
|
71 | 71 | 'name': 'PostgreSQL replication lag in second',
|
72 | 72 | 'items': [
|
73 | 73 | {'color': 'CC0000',
|
74 |
| - 'key': 'pgsql.replication_lag[sec]'}]}) |
| 74 | + 'key': self.right_type(self.key_replication, "sec")}]}) |
75 | 75 | result += template.graph({
|
76 | 76 | 'name': 'PostgreSQL count of xlog files',
|
77 | 77 | 'items': [
|
78 | 78 | {'color': 'CC0000',
|
79 |
| - 'key': self.right_type(self.key_count_wall)}]}) |
| 79 | + 'key': self.right_type(self.key_count_wall)}]}) |
80 | 80 | return result
|
81 | 81 |
|
82 | 82 | def triggers(self, template):
|
83 | 83 | return template.trigger({
|
84 | 84 | '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') |
88 | 88 | })
|
89 | 89 |
|
90 | 90 | def keys_and_queries(self, template_zabbix):
|
91 | 91 | result = []
|
92 | 92 | 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])) |
94 | 95 | result.append('{0},$2 $1 -c "{1}"'.format(self.key_wall.format('[*]'), self.query_xlog_lsn_diff))
|
95 | 96 | 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])) |
97 | 99 | result.append('{0},$2 $1 -c "{1}"'.format(self.key_wall.format('[*]'), self.query_wal_lsn_diff))
|
98 | 100 | # FIXME for lag
|
| 101 | + result.append( |
| 102 | + '{0},$2 $1 -c "{1}"'.format("pgsql.replication_lag.sec[*]", Pooler.SQL['replication_lag_slave_query'])) |
99 | 103 | return template_zabbix.key_and_query(result)
|
100 |
| - |
|
0 commit comments