Monitoring a process for high memory consumption using Monit


I run Pi-hole on an old PogoPlug E02 with a custom compiled dnsmasq (or pihole-FTL, as they now call their customised version of it). Lately I have been noticing my DNS queries becoming slow erratically, and upon further investigation it looked like pihole-FTL has a memory balloon, and it consumes all of the 256 MBs of memory available and starts swapping, bringing everything to an almost standstill.

In comes Monit, a highly configurable process supervisor. This is how I set up monitoring for the errant pihole-FTL process. It checks whether the process consumes more than 100 MB of memory for more than three cycles, and if it does, it restarts it. This has taken care of any sort of manual tinkering I need to do whenever there’s complaints of the internet being slow.

PS: Monit has nice commands to check the status of the processes/files/directories, etc. it monitors. monit summary for succinct information, or monit status for more verbose output. Note that you might need to turn on the HTTP API for these to work.