当系统内存耗尽时需要应用程序/脚本警报

hum*_*ins 1 notification monitoring ram

我不会不使用交换文件(由于内核或 AMD 驱动程序中的一些错误)。

我不想让一些 util 运行和监视可用系统内存并在它低于某个指定限制时提醒我。

这将通知我我需要关闭一些应用程序(或浏览器选项卡)以避免由于一些奇怪的 kswapd0 I/O 活动(可能是另一个错误)导致系统冻结。

有没有合适的软件?

更新:

我重新设计了 Gary 提供的脚本以满足我的需要并想分享它

#!/bin/bash

#Minimum available memory limit, MB
THRESHOLD=400

#Check time interval, sec
INTERVAL=30

while :
do

    free=$(free -m|awk '/^Mem:/{print $4}')
    buffers=$(free -m|awk '/^Mem:/{print $6}')
    cached=$(free -m|awk '/^Mem:/{print $7}')
    available=$(free -m | awk '/^-\/+/{print $4}')

    message="Free $free""MB"", buffers $buffers""MB"", cached $cached""MB"", available $available""MB"""

    if [ $available -lt $THRESHOLD ]
        then
        notify-send "Memory is running out!" "$message"
    fi

    echo $message

    sleep $INTERVAL

done
Run Code Online (Sandbox Code Playgroud)

Gar*_*ary 5

您可以尝试使用free.

free -s n将每秒钟更新一次输出n。将它包装在if您认为使用“太多内存”的任何阈值中,并在达到该点时显示一条消息。

编辑:这是我想出的脚本。粗糙,但它的工作原理。

#Checks for low memory.

#!/bin/bash

#cutoff_frac is basically how much used memory can be at in terms of how much
#total memory you have...2 is 1/2 of 100% or an alert when you're using 50% mem, etc.
cutoff_frac=2

total_mem=$(free|awk '/^Mem:/{print $2}')
let "threshold = $total_mem / $cutoff_frac"

while :
do

    free_mem=$(free|awk '/^Mem:/{print $4}')

    if [ $free_mem -lt $threshold ]
        then
        notify-send "Low memory!!"
    fi

    sleep 5

done

exit
Run Code Online (Sandbox Code Playgroud)