Last modified: 2014-08-17 17:44:24 UTC
There should be a function tools.replag() (can MySQL tie functions to a database?) that provides the replication lag in seconds, and maybe another function tools.lastrepupdate() that returns "NOW() - replag()". It should be a "SECURITY DEFINER" function that queries "SHOW SLAVE STATUS.Seconds_Behind_Master" (cf. mediawiki/core:includes/db/DatabaseMysql.php). This is preferable to the Toolserver method of querying recentchanges as it gives a more accurate picture of the actual replication lag. http://stackoverflow.com/questions/1570776/how-to-access-seconds-behind-master-from-sql has some information that this query should be possible, though not trivial.
I wondered what effect multi-hop replication like in LabsDB (production DBs => sanitizer => LabsDB) has on Seconds_Behind_Master, and Sean said that for this reason WMF uses http://www.percona.com/doc/percona-toolkit/2.2/pt-heartbeat.html. So a database function as proposed in this bug should probably query the heartbeat record instead.