Jump to content

Swap-watchdog

From Wikitech

Quickie script Domas threw together for the PDF service to reboot the box when memory leaks start killing swap. Ideally we'll get the leak sorted out soon!

#!/usr/bin/python

import time

threshold=0.1

while True:
        swapused=0
        for line in open("/proc/swaps"):
                filename,type,size,used,priority=line.strip().split()
                if filename=="Filename": continue
                if int(used) > int(size)*threshold:
                        open("/proc/sysrq-trigger","w").write("b\n")
                        sys.exit(0)
        time.sleep(3)