-
Notifications
You must be signed in to change notification settings - Fork 0
/
flomem
59 lines (47 loc) · 1.78 KB
/
flomem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Load configuration
source "$HOME/.config/floflis/flomem/config.sh"
# Temporary file to count threshold breaches
THRESHOLD_COUNT_FILE="/tmp/flomem_threshold_count"
if [ ! -f "$THRESHOLD_COUNT_FILE" ]; then
echo 0 > "$THRESHOLD_COUNT_FILE"
fi
# Function to get the total and used memory
get_memory_usage() {
total_mem=$(free -m | awk '/^Mem:/ { print $2 }')
used_mem=$(free -m | awk '/^Mem:/ { print $3 }')
percent_used=$(( 100 * $used_mem / $total_mem ))
}
# Function to send notification
send_notification() {
notify-send "High Memory Usage Alert" "Memory usage has reached $percent_used%!"
}
while true; do
get_memory_usage
echo "Total Memory: ${total_mem}MB"
echo "Used Memory: ${used_mem}MB"
echo "Memory Usage: ${percent_used}%"
for i in "${!THRESHOLDS[@]}"; do
threshold=${THRESHOLDS[i]}
action_script=${ACTION_SCRIPTS[i]}
if [ $percent_used -gt $threshold ]; then
send_notification
$action_script
# Increment the threshold count
threshold_count=$(cat $THRESHOLD_COUNT_FILE)
threshold_count=$((threshold_count + 1))
echo $threshold_count > $THRESHOLD_COUNT_FILE
# Check if the count has reached the max threshold
if [ $threshold_count -ge $MAX_THRESHOLD_REACHED ]; then
notify-send "High Memory Usage Alert" "Memory usage has reached the threshold $MAX_THRESHOLD_REACHED times. Please consider restarting your computer."
fi
fi
done
sleep 3 # Check every 3 seconds for the action
if (( SECONDS % 60 == 0 )); then
get_memory_usage
echo "Total Memory: ${total_mem}MB"
echo "Used Memory: ${used_mem}MB"
echo "Memory Usage: ${percent_used}%"
fi
done