The rest of this recipe assumes that you have enabled hot_standby. This is not an absolute requirement, but it makes things much, much easier.
Both repmgr and pgpool provide replication monitoring facilities. Munin plugins are available for graphing replication and apply delay.
Replication works by processing the WAL transaction log on other servers. You can think of WAL as a single, serialized stream of messages. Each message in the WAL is identified by an 8-byte integer known as a Log Sequence Number (LSN). For historical reasons, we show this as two separate hex numbers; for example, the LSN value X is shown as XXXX/YYYY.
You can compare any two LSNs using pg_wal_lsn_diff(). In some places, prior to PostgreSQL 10, an LSN ...