Skip to content

Commit

Permalink
Add memory monitor script (getumbrel#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds authored Jun 10, 2021
1 parent 86a4c73 commit 95e4437
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scripts/debug
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ free --human --mega
echo
"${UMBREL_ROOT}/scripts/memory-usage"

echo
echo "Memory monitor logs"
echo "-------------------"
tail -n 10 "${UMBREL_ROOT}/logs/memory-monitor.log"

echo
echo "Filesystem information"
Expand Down
31 changes: 31 additions & 0 deletions scripts/memory-monitor
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

UMBREL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/..)"

PERCENT_MEMORY_THRESHOLD=90

check_if_not_already_running() {
if ps ax | grep $0 | grep -v $$ | grep bash | grep -v grep
then
echo "Memory monitor is already running"
exit 1
fi
}

log () {
echo "$(date "+%Y-%m-%d %H:%M:%S") ${@}"
}

check_if_not_already_running
log "Memory monitor running!"

while true; do
percent_memory_used=$(free | awk 'NR==2{print int($3*100/$2) }')
if (( $percent_memory_used > $PERCENT_MEMORY_THRESHOLD )); then
log "Warning memory usage at ${percent_memory_used}%"
if [[ "$(jq -r '.installedApps | length > 0' ${UMBREL_ROOT}/db/user.json)" == "true" ]]; then
touch "${UMBREL_ROOT}/statuses/memory-warning"
fi
fi
sleep 60
done
4 changes: 4 additions & 0 deletions scripts/start
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ echo "Starting karen..."
echo
./karen &>> "${UMBREL_LOGS}/karen.log" &

echo "Starting memory monitor..."
echo
./scripts/memory-monitor &>> "${UMBREL_LOGS}/memory-monitor.log" &

echo "Starting backup monitor..."
echo
./scripts/backup/monitor &>> "${UMBREL_LOGS}/backup-monitor.log" &
Expand Down

0 comments on commit 95e4437

Please sign in to comment.