Sunday, April 28, 2024
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 7201  / 2 Years ago, thu, november 18, 2021, 3:59:25

I don't won't to use swap file (due to some bug in kernel or AMD driver).



I wan't to have some util running and monitoring free system memory and alerting me when it becomes less than some specified limit.



This will notify me that I need to close some applications (or browser tabs) to avoid system freeze due to some strange kswapd0 I/O activity (probably another bug).



Is there any appropriate software?



UPDATE:



I've redesigned script provided by Gary for my need and want to share it



#!/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

More From » notification

 Answers
3

You could try using free.



free -s n will update the output every n seconds. Wrap that in an if for whatever threshold you feel is "too much memory" being used, and display a message when it reaches that point.



EDIT: Here's the script I came up with. Rough, but it works.



#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

[#31959] Friday, November 19, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
istmasted

Total Points: 287
Total Questions: 130
Total Answers: 153

Location: Burkina Faso
Member since Thu, Dec 23, 2021
2 Years ago
istmasted questions
;