2020-07-23 16:47:18 +02:00
|
|
|
#!/usr/bin/env bash
|
2020-06-04 05:44:17 +02:00
|
|
|
|
|
|
|
get_percent()
|
|
|
|
{
|
|
|
|
case $(uname -s) in
|
|
|
|
Linux)
|
2020-06-07 04:41:30 +02:00
|
|
|
# percent=$(free -m | awk 'NR==2{printf "%.1f%%\n", $3*100/$2}')
|
|
|
|
used_mem=$(free -g | grep Mem: | awk '{mem += $3} END {print mem}')
|
|
|
|
total_mem=$(free -h | grep Mem: | awk '{mem += $2} END {print mem}')
|
|
|
|
if (( $used_mem == 0 )); then
|
|
|
|
memory_usage=$(free -m | grep Mem: | awk '{mem += $3} END {print mem}')
|
|
|
|
echo $memory_usage\M\B/$total_mem\G\B
|
|
|
|
else
|
|
|
|
memory_usage=$(free -g | grep Mem: | awk '{mem += $3} END {print mem}')
|
|
|
|
echo $memory_usage\G\B/$total_mem\G\B
|
|
|
|
fi
|
2020-06-04 05:44:17 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
Darwin)
|
2020-06-07 04:41:30 +02:00
|
|
|
# percent=$(ps -A -o %mem | awk '{mem += $1} END {print mem}')
|
2020-07-23 16:45:49 +02:00
|
|
|
# Get used memory blocks with vm_stat, multiply by 4096 to get size in bytes, then convert to MiB
|
2020-07-24 05:12:23 +02:00
|
|
|
used_mem=$(vm_stat | grep ' active\|wired ' | sed 's/[^0-9]//g' | paste -sd ' ' - | awk '{printf "%d\n", ($1+$2) * 4096 / 1048576}')
|
2020-06-14 03:42:27 +02:00
|
|
|
total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}')
|
|
|
|
if (( $used_mem < 1024 )); then
|
|
|
|
echo $used_mem\M\B/$total_mem
|
|
|
|
else
|
2020-06-28 19:34:08 +02:00
|
|
|
memory=$(($used_mem/1024))
|
2020-06-14 03:42:27 +02:00
|
|
|
echo $memory\G\B/$total_mem
|
|
|
|
fi
|
2020-06-04 05:44:17 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
|
|
|
# TODO - windows compatability
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
ram_percent=$(get_percent)
|
|
|
|
echo "RAM $ram_percent"
|
2020-08-09 07:50:07 +02:00
|
|
|
sleep $RATE
|
2020-06-04 05:44:17 +02:00
|
|
|
}
|
2020-06-04 06:33:47 +02:00
|
|
|
|
2020-06-04 05:44:17 +02:00
|
|
|
#run main driver
|
|
|
|
main
|