|
9 | 9 |
|
10 | 10 |
|
11 | 11 | class Wal(Plugin):
|
12 |
| - AgentPluginType = "pg" |
| 12 | + AgentPluginType = "pgsql" |
13 | 13 | DEFAULT_CONFIG = {
|
14 | 14 | "lag_more_than_in_sec": str(60 * 5)
|
15 | 15 | }
|
@@ -53,6 +53,8 @@ class Wal(Plugin):
|
53 | 53 | key_flush = "pgsql.replication.flush_lag{0}"
|
54 | 54 | key_replay = "pgsql.replication.replay_lag{0}"
|
55 | 55 | key_write = "pgsql.replication.write_lag{0}"
|
| 56 | + key_send = "pgsql.replication.send_lag{0}" |
| 57 | + key_receive = "pgsql.replication.receive_lag{0}" |
56 | 58 |
|
57 | 59 | # keys for PG 14 and higher
|
58 | 60 | key_wal_records = "pgsql.wal.records.count{0}"
|
@@ -84,15 +86,23 @@ def run(self, zbx):
|
84 | 86 | if Pooler.server_version_greater("10.0"):
|
85 | 87 | result = Pooler.query(self.query_wal_lsn_diff)
|
86 | 88 | result_lags = Pooler.run_sql_type("wal_lag_lsn",
|
87 |
| - args=[" flush_lag, replay_lag, write_lag, ", "wal", "lsn"]) |
| 89 | + args=[" (pg_wal_lsn_diff(pg_current_wal_lsn(), sent_lsn))::int AS send_lag, " |
| 90 | + "(pg_wal_lsn_diff(sent_lsn, flush_lsn))::int AS receive_lag, " |
| 91 | + "(pg_wal_lsn_diff(sent_lsn, write_lsn))::int AS write_lag, " |
| 92 | + "(pg_wal_lsn_diff(write_lsn, flush_lsn))::int AS flush_lag, " |
| 93 | + "(pg_wal_lsn_diff(flush_lsn, replay_lsn))::int AS replay_lag, " if not Pooler.is_bootstraped() else |
| 94 | + " send_lag, receive_lag, write_lag, flush_lag, replay_lag, ", |
| 95 | + "wal", "lsn"]) |
88 | 96 | if result_lags:
|
89 | 97 | lags = []
|
90 | 98 | for info in result_lags:
|
91 | 99 | lags.append({"{#APPLICATION_NAME}": info[0]})
|
92 |
| - zbx.send("pgsql.replication.flush_lag[{0}]".format(info[0]), info[1]) |
93 |
| - zbx.send("pgsql.replication.replay_lag[{0}]".format(info[0]), info[2]) |
| 100 | + zbx.send("pgsql.replication.send_lag[{0}]".format(info[0]), info[1]) |
| 101 | + zbx.send("pgsql.replication.receive_lag[{0}]".format(info[0]), info[2]) |
94 | 102 | zbx.send("pgsql.replication.write_lag[{0}]".format(info[0]), info[3])
|
95 |
| - zbx.send("pgsql.replication.total_lag[{0}]".format(info[0]), float(info[4])) |
| 103 | + zbx.send("pgsql.replication.flush_lag[{0}]".format(info[0]), info[4]) |
| 104 | + zbx.send("pgsql.replication.replay_lag[{0}]".format(info[0]), info[5]) |
| 105 | + zbx.send("pgsql.replication.total_lag[{0}]".format(info[0]), float(info[6])) |
96 | 106 | zbx.send("pgsql.replication.discovery[]", zbx.json({"data": lags}))
|
97 | 107 | del lags
|
98 | 108 | else:
|
@@ -242,22 +252,33 @@ def discovery_rules(self, template, dashboard=False):
|
242 | 252 | ]
|
243 | 253 | }]
|
244 | 254 | items = [
|
| 255 | + {"key": self.right_type(self.key_send, var_discovery="{#APPLICATION_NAME},"), |
| 256 | + "name": "Time elapsed sending recent WAL locally on {#APPLICATION_NAME}", |
| 257 | + "value_type": Plugin.VALUE_TYPE.numeric_float, |
| 258 | + "delay": self.plugin_config("interval"), |
| 259 | + "drawtype": 2}, |
| 260 | + {"key": self.right_type(self.key_receive, var_discovery="{#APPLICATION_NAME},"), |
| 261 | + "name": "Time elapsed between receiving recent WAL locally and receiving notification that " |
| 262 | + "this standby server {#APPLICATION_NAME} has flushed it", |
| 263 | + "value_type": Plugin.VALUE_TYPE.numeric_float, |
| 264 | + "delay": self.plugin_config("interval"), |
| 265 | + "drawtype": 2}, |
| 266 | + {"key": self.right_type(self.key_write, var_discovery="{#APPLICATION_NAME},"), |
| 267 | + "name": "Time elapsed between flushing recent WAL locally and receiving notification that " |
| 268 | + "this standby server {#APPLICATION_NAME} has written it", |
| 269 | + "value_type": Plugin.VALUE_TYPE.numeric_float, |
| 270 | + "delay": self.plugin_config("interval"), |
| 271 | + "drawtype": 2}, |
245 | 272 | {"key": self.right_type(self.key_flush, var_discovery="{#APPLICATION_NAME},"),
|
246 | 273 | "name": "Time elapsed between flushing recent WAL locally and receiving notification that "
|
247 | 274 | "this standby server {#APPLICATION_NAME} has written and flushed it",
|
248 |
| - "value_type": Plugin.VALUE_TYPE.text, |
| 275 | + "value_type": Plugin.VALUE_TYPE.numeric_float, |
249 | 276 | "delay": self.plugin_config("interval"),
|
250 | 277 | "drawtype": 2},
|
251 | 278 | {"key": self.right_type(self.key_replay, var_discovery="{#APPLICATION_NAME},"),
|
252 | 279 | "name": "Time elapsed between flushing recent WAL locally and receiving notification that "
|
253 | 280 | "this standby server {#APPLICATION_NAME} has written, flushed and applied",
|
254 |
| - "value_type": Plugin.VALUE_TYPE.text, |
255 |
| - "delay": self.plugin_config("interval"), |
256 |
| - "drawtype": 2}, |
257 |
| - {"key": self.right_type(self.key_write, var_discovery="{#APPLICATION_NAME},"), |
258 |
| - "name": "Time elapsed between flushing recent WAL locally and receiving notification that " |
259 |
| - "this standby server {#APPLICATION_NAME} has written it", |
260 |
| - "value_type": Plugin.VALUE_TYPE.text, |
| 281 | + "value_type": Plugin.VALUE_TYPE.numeric_float, |
261 | 282 | "delay": self.plugin_config("interval"),
|
262 | 283 | "drawtype": 2},
|
263 | 284 | {"key": self.right_type(self.key_total_lag, var_discovery="{#APPLICATION_NAME},"),
|
|
0 commit comments