Skip to content

Commit

Permalink
memory-monitor: Fix log files clean up to prevent storage overflow.
Browse files Browse the repository at this point in the history
Fix an issue where the memory-monitor-handler.sh script could fail to
correctly calculate the total size of archives and logs due to
inconsistent references to log file names.

This prevents the device from being flooded with memory-monitor output
files that consume excessive storage space.

Signed-off-by: Nikolay Martyanov <nikolay@zededa.com>
  • Loading branch information
OhmSpectator committed Oct 10, 2024
1 parent ea0fee9 commit dbffd95
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/memory-monitor/src/monitor/memory-monitor-handler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,12 @@ for dir in */; do
fi
done

MEMORY_MONITOR_HANDLER_LOG_FILE="memory-monitor-handler.log"

# Remove old archives, do not keep more than 100 MB of archives
total_size=$(du -s | awk '{print $1}') # Size in KB
# Subtract the size of the handler log file
total_size=$((total_size - $(stat -c %s memory-monitor-handler.log) / 1024))
total_size=$((total_size - $(stat -c %s "$MEMORY_MONITOR_HANDLER_LOG_FILE") / 1024))
# Subtract the size of the psi.txt file (if it exists) as it size is regulated by the PSICollector
if [ -f psi.txt ]; then
total_size=$((total_size - $(stat -c %s psi.txt) / 1024))
Expand All @@ -201,5 +203,5 @@ while [ "$total_size" -gt 102400 ]; do
# Remove the first line from the events.log file: it contains the oldest event info
sed -i '1d' events.log
total_size=$(du -s | awk '{print $1}')
total_size=$((total_size - $(stat -c %s handler.log) / 1024))
total_size=$((total_size - $(stat -c %s "$MEMORY_MONITOR_HANDLER_LOG_FILE") / 1024))
done

0 comments on commit dbffd95

Please sign in to comment.