metrics.sh/metrics/memory.sh

21 lines
490 B
Bash
Raw Normal View History

2015-02-19 14:15:38 -05:00
#!/bin/sh
2015-02-21 12:18:27 -05:00
2015-02-22 12:36:04 -05:00
if [ $OS_TYPE == "osx" ]; then
# FIXME: total_memory leaks out
total_memory=$(sysctl -n hw.memsize)
collect () {
echo $(vm_stat | awk -v total_memory=$total_memory \
'BEGIN {FS=" *"; pages=0}
/Pages (free|inactive|speculative)/ {pages+=$2}
END {printf "%.2f", 100 - (pages * 4096) / total_memory * 100.0}')
}
else
collect () {
echo $(free | awk '/buffers\/cache/{printf "%.2f", $4 / ($3 + $4) * 100.0}')
}
fi