add commands for osx
This commit is contained in:
parent
a827a71513
commit
8957cb4387
10
lib/utils.sh
10
lib/utils.sh
|
@ -1,3 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
# http://stackoverflow.com/a/1369211/183097
|
||||
copy_function () {
|
||||
declare -F $1 > /dev/null || return 1
|
||||
|
@ -7,3 +9,11 @@ copy_function () {
|
|||
is_function () {
|
||||
[ "`type -t $1`" == 'function' ]
|
||||
}
|
||||
|
||||
OS_TYPE=$(case "$OSTYPE" in
|
||||
(solaris*) echo solaris;;
|
||||
(darwin*) echo osx;;
|
||||
(linux*) echo linux;;
|
||||
(bsd*) echo bsd;;
|
||||
(*) echo unknown;;
|
||||
esac)
|
|
@ -1,5 +1,21 @@
|
|||
#!/bin/sh
|
||||
|
||||
collect () {
|
||||
echo $(free | awk '/buffers\/cache/{print $4/($3+$4) * 100.0;}')
|
||||
}
|
||||
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
|
|
@ -1,5 +1,15 @@
|
|||
#!/bin/sh
|
||||
|
||||
collect () {
|
||||
echo $(free | awk '/Swap/{print $3/$2 * 100.0;}')
|
||||
}
|
||||
if [ $OS_TYPE == "osx" ]; then
|
||||
|
||||
collect () {
|
||||
echo $(sysctl -n vm.swapusage | awk '{printf "%.2f", $6 / $3 * 100.0}')
|
||||
}
|
||||
|
||||
else
|
||||
|
||||
collect () {
|
||||
echo $(free | awk '/Swap/{printf "%.2f", $3/$2 * 100.0;}')
|
||||
}
|
||||
|
||||
fi
|
Loading…
Reference in New Issue