metrics.sh/metrics/memory.sh

20 lines
515 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
declare -r __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 () {
report $(free | awk '/buffers\/cache/{printf "%.1f", 100 - $4 / ($3 + $4) * 100.0}')
2015-02-22 12:36:04 -05:00
}
fi
docs () {
echo "Percentage of used memory."
}