I'd like to monitor mysql replication delay with monit using the pt-heartbeat tool. The tool writes the replication delay in seconds to a file. The file is a single line like: 12.00
The file is opened, truncated, and closed every interval, so it will only contain the most recent statistics. My first thought was to use monit's file timestamp check like this[1], but I realise the file will be updated every check, no matter whether the replication is up to date or not. Second thought, use the file content check. However, I realise that is unlikely to work because, from the monit man page: On startup the read position is set to the end of the file and Monit continue to scan to the end of file on each cycle. But if the file size should decrease or inode change the read position is set to the start of the file. As per above, the file inode or size are unlikely to change. So monit will most likely never read the changes. That leaves 2 options I can think of. Option 1 is to write a script, if the logged replication delay is < threshold, exit 0, if not, exit 1. Then use monit's exit status check. However, this moves the check logic out of monit into another script and reduces the available information in the monit dashboard. Option 2 would be to use the approach outlined here[1]. So if the replication delay is < some threshold, touch a file. Then use monit's timestamp checking to alert if that file gets too old. Any advice on which of these options to pursue? Anyone else doing this or any tutorials / code samples online somewhere? I'd be grateful for any input / ideas on this one. Love & joy - Callum. [1] http://www.elevatedcode.com/articles/2007/12/05/replication-monitoring-with-monit/ -- To unsubscribe: https://lists.nongnu.org/mailman/listinfo/monit-general
