write sysctl version for free bsd
This commit is contained in:
17
bin/st-mem
17
bin/st-mem
@ -1,3 +1,18 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
MEMORY_USED=$(free -h | awk 'NR==2 {print $3}')
|
#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
|
echo $MEMORY_USED
|
||||||
|
|||||||
Reference in New Issue
Block a user