metrics.sh/metrics/memory.sh

24 lines
541 B
Bash
Raw Normal View History

2015-02-19 14:15:38 -05:00
#!/bin/sh
2015-02-21 12:18:27 -05:00
if is_osx; then
start () {
readonly __memory_os_memsize=$(sysctl -n hw.memsize)
}
2015-02-22 12:36:04 -05:00
collect () {
report $(vm_stat | awk -v total_memory=$__memory_os_memsize \
'BEGIN { FS=" *"; pages=0 }
/Pages (free|inactive|speculative)/ { pages+=$2 }
END { printf "%.1f", 100 - (pages * 4096) / total_memory * 100.0 }')
2015-02-22 12:36:04 -05:00
}
else
collect () {
2017-10-09 08:54:57 -04:00
report $(free | awk '/Mem:/ {
printf "%.1f", 100 - $4 / ($3 + $4) * 100}')
2015-02-22 12:36:04 -05:00
}
fi
docs () {
echo "Percentage of used memory."
2017-10-09 08:54:57 -04:00
}