Skip to content

Commit ea19764

Browse files
authored
Merge branch 'main' into PMM-14260
2 parents 2d0f4ce + 4c057a6 commit ea19764

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

queries-hr.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,30 @@ pg_custom_replication_wal:
8989
master: true
9090
query: |
9191
SELECT
92-
pg_last_wal_receive_lsn() AS received_lsn,
93-
pg_last_wal_replay_lsn() AS replayed_lsn,
94-
pg_current_wal_lsn() AS current_lsn,
95-
pg_current_wal_lsn() - pg_last_wal_replay_lsn() AS lag_bytes;
92+
CASE WHEN pg_is_in_recovery() THEN 'replica' ELSE 'primary' END AS node_type,
93+
CASE WHEN pg_is_in_recovery() THEN pg_last_wal_receive_lsn() ELSE NULL END AS received_lsn,
94+
CASE WHEN pg_is_in_recovery() THEN pg_last_wal_replay_lsn() ELSE NULL END AS replayed_lsn,
95+
CASE WHEN pg_is_in_recovery() THEN NULL ELSE pg_current_wal_lsn() END AS current_lsn,
96+
CASE
97+
WHEN pg_is_in_recovery() THEN pg_last_wal_receive_lsn() - pg_last_wal_replay_lsn()
98+
ELSE NULL
99+
END AS lag_bytes
96100
metrics:
101+
- node_type:
102+
usage: "LABEL"
103+
description: "Type of node (primary or replica)."
97104
- received_lsn:
98105
usage: "GAUGE"
99-
description: "Last WAL location received by the standby server."
106+
description: "Last WAL location received by the standby server (replica only)."
100107
- replayed_lsn:
101108
usage: "GAUGE"
102-
description: "Last WAL location replayed by the standby server."
109+
description: "Last WAL location replayed by the standby server (replica only)."
103110
- current_lsn:
104111
usage: "GAUGE"
105-
description: "Current WAL location on the primary server."
112+
description: "Current WAL location on the primary server (primary only)."
106113
- lag_bytes:
107114
usage: "GAUGE"
108-
description: "Current WAL replication lag in bytes."
115+
description: "Current WAL replication lag in bytes (replica only)."
109116

110117
pg_custom_stat_replication:
111118
master: true

0 commit comments

Comments
 (0)