Notifications when dom0 or Xen memory is low

Original forum link
https://forum.qubes-os.org/t/23797
Original poster
ddevz
Created at
2024-01-11 20:11:52
Posts count
14
Likes count
5

Split from the Quick Quality-of-Life Improvements thread

 

Putting this in cron for every 5 min in dom0 can warn you before the system grinds to a halt because of dom0 memory. (adjust the the "4" to whatever you want your memory threshold to be in gigs, and adjust the expire time (in miliseconds))

FREE_MEMORY=$((`free -g | grep '^Mem' | awk '{print $7}'`))
if (( $FREE_MEMORY < 4 )); then
    notify-send  --expire-time=360000 --urgency=critical 'RUNNING OUT OF DOM0 MEMORY!!!!!!' "DOM0 memory is down to $FREE_MEMORY Gigs...  DO SOMETHING!!!!! :) "
fi

Similarly, putting this in cron to run every 5 min in dom0 can warn you before the system runs out of xen memory for new qubes. (adjust the the "8" to whatever you want your memory threshold to be in gigs, and adjust the expire time (in miliseconds)) (note: this situation was a bigger problem in qubes 4.1 then qubes 4.2)

FREE_MEMORY=$((`xl info | grep free_memory | sed 's/^.*:\([0-9]*\)/\1/'` / 1000))
if (( $FREE_MEMORY < 8 )); then
    notify-send --expire-time=360000 --urgency=critical 'RUNNING OUT OF XEN MEMORY!' "Xen memory is down to $FREE_MEMORY Gigs...  Kill some VM's!"
fi