Skip to content

Commit 81dadc4

Browse files
committed
fix: fixed Slave Replication Lag metric to exclude master server from calculation
1 parent 151c66e commit 81dadc4

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

mamonsu/plugins/pgsql/driver/pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Pool(object):
1717
),
1818
"replication_lag_slave_query": (
1919
"""
20-
SELECT CASE WHEN coalesce(pg_last_{1}(), '0/00000000') = coalesce(pg_last_{2}(), '0/00000000')
20+
SELECT CASE WHEN NOT pg_is_in_recovery() OR coalesce(pg_last_{1}(), '0/00000000') = coalesce(pg_last_{2}(), '0/00000000')
2121
THEN 0
2222
ELSE extract (epoch FROM now() - coalesce(pg_last_xact_replay_timestamp(), now() - INTERVAL '{0} seconds'))
2323
END;

mamonsu/plugins/pgsql/xlog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Xlog(Plugin):
2323
"""
2424
# get time of replication lag
2525
query_agent_replication_lag = """
26-
SELECT CASE WHEN coalesce(pg_last_{1}(), '0/00000000') = coalesce(pg_last_{2}(), '0/00000000')
26+
SELECT CASE WHEN NOT pg_is_in_recovery() OR coalesce(pg_last_{1}(), '0/00000000') = coalesce(pg_last_{2}(), '0/00000000')
2727
THEN 0
2828
ELSE extract (epoch FROM now() - coalesce(pg_last_xact_replay_timestamp(), now() - INTERVAL '{0} seconds'))
2929
END;

mamonsu/tools/bootstrap/sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
CREATE OR REPLACE FUNCTION mamonsu.timestamp_get()
5050
RETURNS double precision AS $$
5151
SELECT
52-
CASE WHEN pg_last_{11}() = pg_last_{12}() THEN 0
52+
CASE WHEN NOT pg_is_in_recovery() OR pg_last_{11}() = pg_last_{12}() THEN 0
5353
ELSE extract (epoch FROM now() - coalesce(pg_last_xact_replay_timestamp(), to_timestamp(ts)))
5454
END
5555
FROM mamonsu.timestamp_master_{1}

0 commit comments

Comments
 (0)