Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

nagios: `pg_is_in_recovery()` is better to know replica/primary status.

Alex Vandiver610a0b2d5992
diff --git a/puppet/zulip/files/nagios_plugins/zulip_postgresql/check_postgresql_replication_lag b/puppet/zulip/files/nagios_plugins/zulip_postgresql/check_postgresql_replication_lag
index 38ba6b5ae06..9c3c4dcbfcb 100755
--- a/puppet/zulip/files/nagios_plugins/zulip_postgresql/check_postgresql_replication_lag
+++ b/puppet/zulip/files/nagios_plugins/zulip_postgresql/check_postgresql_replication_lag
@@ -76,27 +76,30 @@ def loc_to_abs_offset(loc_str: str) -> int:
return 0xFF000000 * int(xlog_file, 16) + int(file_offset, 16)
-replication_info = run_sql_query(
- "sender_host, status, pg_last_wal_replay_lsn(), pg_last_wal_receive_lsn()"
- " from pg_stat_wal_receiver"
-)
+is_in_recovery = run_sql_query("pg_is_in_recovery()")
-if replication_info:
- (primary_server, state, replay_loc, recv_loc) = replication_info[0]
-
- recv_offset = loc_to_abs_offset(recv_loc)
- replay_lag = recv_offset - loc_to_abs_offset(replay_loc)
-
- if state != "streaming":
- report("CRITICAL", f"replica is in state {state}, not streaming")
-
- msg = f"replica is {replay_lag} bytes behind in replay of WAL logs from {primary_server}"
- if replay_lag > 5 * 16 * 1024 ** 2:
- report("CRITICAL", msg)
- elif replay_lag > 16 * 1024 ** 2:
- report("WARNING", msg)
+if is_in_recovery[0][0] == "t":
+ replication_info = run_sql_query(
+ "sender_host, status, pg_last_wal_replay_lsn(), pg_last_wal_receive_lsn()"
+ " from pg_stat_wal_receiver"
+ )
+ if not replication_info:
+ report("CRITICAL", "Replaying WAL logs from backups")
else:
- report("OK", msg)
+ (primary_server, state, replay_loc, recv_loc) = replication_info[0]
+ recv_offset = loc_to_abs_offset(recv_loc)
+ replay_lag = recv_offset - loc_to_abs_offset(replay_loc)
+
+ if state != "streaming":
+ report("CRITICAL", f"replica is in state {state}, not streaming")
+
+ msg = f"replica is {replay_lag} bytes behind in replay of WAL logs from {primary_server}"
+ if replay_lag > 5 * 16 * 1024 ** 2:
+ report("CRITICAL", msg)
+ elif replay_lag > 16 * 1024 ** 2:
+ report("WARNING", msg)
+ else:
+ report("OK", msg)
else:
replication_info = run_sql_query(