19 lines
642 B
Bash
Executable File
19 lines
642 B
Bash
Executable File
#!/bin/sh
|
|
MEMORY_USED=$(free -h | awk 'NR==2 {print $3}')
|
|
|
|
# freebsd (and maybe better for linux too)
|
|
#PAGES_WIRED=$(sysctl vm.stats.vm.v_wire_count | awk '{print $2}')
|
|
#PAGES_ACTIVE=$(sysctl vm.stats.vm.v_active_count | awk '{print $2}')
|
|
#PAGES_DIRTY=$(sysctl vm.stats.vm.v_laundry_count | awk '{print $2}')
|
|
#TOTAL_PAGES=$(echo "scale=0; $PAGES_WIRED+$PAGES_ACTIVE+$PAGES_DIRTY" | bc)
|
|
#
|
|
#BYTES_USED=$(echo "scale=0; $TOTAL_PAGES*4096" | bc)
|
|
#
|
|
#if [ $BYTES_USED -ge 1073741824 ]; then
|
|
# MEMORY_USED="$(echo "scale=1; $BYTES_USED/1024^3" | bc) GiB"
|
|
#else
|
|
# MEMORY_USED="$(echo "scale=1; $BYTES_USED/1024^2" | bc) MiB"
|
|
#fi
|
|
|
|
echo $MEMORY_USED
|