mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-21 22:13:19 -07:00
Add FreeBSD uptime, fix formatting again
This commit is contained in:
parent
262906b6c1
commit
6f577c0610
2 changed files with 69 additions and 68 deletions
|
@ -20,78 +20,78 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
__memory_detail() {
|
__memory_detail() {
|
||||||
free
|
free
|
||||||
}
|
}
|
||||||
|
|
||||||
__memory() {
|
__memory() {
|
||||||
local free="" total="" buffers="" cached=""
|
local free="" total="" buffers="" cached=""
|
||||||
local kb_main_used=0 buffers_plus_cached=0 fo_buffers=0 fo_cached=0
|
local kb_main_used=0 buffers_plus_cached=0 fo_buffers=0 fo_cached=0
|
||||||
|
|
||||||
if [ $(uname) = "Linux" ]; then
|
if [ $(uname) = "Linux" ]; then
|
||||||
if [ -r /proc/meminfo ]; then
|
if [ -r /proc/meminfo ]; then
|
||||||
while read tok val unit; do
|
while read tok val unit; do
|
||||||
case "$tok" in
|
case "$tok" in
|
||||||
MemTotal:) total=${val};;
|
MemTotal:) total=${val};;
|
||||||
MemFree:) free=${val};;
|
MemFree:) free=${val};;
|
||||||
Buffers:) buffers=${val};;
|
Buffers:) buffers=${val};;
|
||||||
Cached:) cached=${val};;
|
Cached:) cached=${val};;
|
||||||
esac
|
esac
|
||||||
[ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break;
|
[ -n "${free}" -a -n "${total}" -a -n "${buffers}" -a -n "${cached}" ] && break;
|
||||||
done < /proc/meminfo
|
done < /proc/meminfo
|
||||||
fi
|
fi
|
||||||
elif [ $(uname) = "FreeBSD" ]; then
|
elif [ $(uname) = "FreeBSD" ]; then
|
||||||
# FreeBSD support
|
# FreeBSD support
|
||||||
mem_phys=$(sysctl -n hw.physmem)
|
mem_phys=$(sysctl -n hw.physmem)
|
||||||
page_size=$(sysctl -n hw.pagesize)
|
page_size=$(sysctl -n hw.pagesize)
|
||||||
mem_inactive=$(($(sysctl -n vm.stats.vm.v_inactive_count)*$page_size))
|
mem_inactive=$(($(sysctl -n vm.stats.vm.v_inactive_count)*$page_size))
|
||||||
mem_cache=$(($(sysctl -n vm.stats.vm.v_cache_count)*$page_size))
|
mem_cache=$(($(sysctl -n vm.stats.vm.v_cache_count)*$page_size))
|
||||||
mem_free=$(($(sysctl -n vm.stats.vm.v_free_count)*$page_size))
|
mem_free=$(($(sysctl -n vm.stats.vm.v_free_count)*$page_size))
|
||||||
|
|
||||||
mem_avail=$(($mem_inactive+$mem_cache+$mem_free))
|
mem_avail=$(($mem_inactive+$mem_cache+$mem_free))
|
||||||
mem_used=$(($mem_phys-$mem_avail))
|
mem_used=$(($mem_phys-$mem_avail))
|
||||||
|
|
||||||
total=$(($mem_phys/1024))
|
total=$(($mem_phys/1024))
|
||||||
free=$(($mem_avail/1024))
|
free=$(($mem_avail/1024))
|
||||||
|
|
||||||
buffers=0
|
buffers=0
|
||||||
cached=0
|
cached=0
|
||||||
elif eval $BYOBU_TEST vm_stat >/dev/null 2>&1; then
|
elif eval $BYOBU_TEST vm_stat >/dev/null 2>&1; then
|
||||||
# MacOS support
|
# MacOS support
|
||||||
# calculation borrowed from http://apple.stackexchange.com/a/48195/18857
|
# calculation borrowed from http://apple.stackexchange.com/a/48195/18857
|
||||||
free_blocks=$(vm_stat | grep free | awk '{ print $3 }' | sed -e 's/\.//')
|
free_blocks=$(vm_stat | grep free | awk '{ print $3 }' | sed -e 's/\.//')
|
||||||
inactive_blocks=$(vm_stat | grep inactive | awk '{ print $3 }' | sed -e 's/\.//')
|
inactive_blocks=$(vm_stat | grep inactive | awk '{ print $3 }' | sed -e 's/\.//')
|
||||||
speculative_blocks=$(vm_stat | grep speculative | awk '{ print $3 }' | sed -e 's/\.//')
|
speculative_blocks=$(vm_stat | grep speculative | awk '{ print $3 }' | sed -e 's/\.//')
|
||||||
free=$((($free_blocks+speculative_blocks)*4))
|
free=$((($free_blocks+speculative_blocks)*4))
|
||||||
inactive=$(($inactive_blocks*4))
|
inactive=$(($inactive_blocks*4))
|
||||||
total=$(($free+$inactive))
|
total=$(($free+$inactive))
|
||||||
buffers=0
|
buffers=0
|
||||||
cached=0
|
cached=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
kb_main_used=$(($total-$free))
|
kb_main_used=$(($total-$free))
|
||||||
buffers_plus_cached=$(($buffers+$cached))
|
buffers_plus_cached=$(($buffers+$cached))
|
||||||
# "free output" buffers and cache (output from 'free')
|
# "free output" buffers and cache (output from 'free')
|
||||||
fo_buffers=$(($kb_main_used - $buffers_plus_cached))
|
fo_buffers=$(($kb_main_used - $buffers_plus_cached))
|
||||||
fpdiv $((100*${fo_buffers})) "${total}" 0;
|
fpdiv $((100*${fo_buffers})) "${total}" 0;
|
||||||
usage=${_RET}
|
usage=${_RET}
|
||||||
|
|
||||||
if [ $total -ge 1048576 ]; then
|
if [ $total -ge 1048576 ]; then
|
||||||
fpdiv "$total" 1048567 1
|
fpdiv "$total" 1048567 1
|
||||||
total=${_RET}
|
total=${_RET}
|
||||||
unit="$ICON_GB"
|
unit="$ICON_GB"
|
||||||
elif [ $total -ge 1024 ]; then
|
elif [ $total -ge 1024 ]; then
|
||||||
fpdiv "$total" 1024 0
|
fpdiv "$total" 1024 0
|
||||||
total=${_RET}
|
total=${_RET}
|
||||||
unit="$ICON_MB"
|
unit="$ICON_MB"
|
||||||
else
|
else
|
||||||
unit="$ICON_KB"
|
unit="$ICON_KB"
|
||||||
fi
|
fi
|
||||||
if [ $usage -gt 90 ]; then
|
if [ $usage -gt 90 ]; then
|
||||||
# Change foreground to yellow, if usage over 90%
|
# Change foreground to yellow, if usage over 90%
|
||||||
fg="Y"
|
fg="Y"
|
||||||
else
|
else
|
||||||
fg="W"
|
fg="W"
|
||||||
fi
|
fi
|
||||||
[ -n "$total" ] || return
|
[ -n "$total" ] || return
|
||||||
color b g W; printf "%s" "$total"; color -; color g W; printf "%s" "$unit"; color -; color b g "$fg"; printf "%s" "$usage"; color -; color g "$fg"; printf "%s" "$PCT"; color --
|
color b g W; printf "%s" "$total"; color -; color g W; printf "%s" "$unit"; color -; color b g "$fg"; printf "%s" "$usage"; color -; color g "$fg"; printf "%s" "$PCT"; color --
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,9 @@ __uptime() {
|
||||||
if [ -r /proc/uptime ]; then
|
if [ -r /proc/uptime ]; then
|
||||||
read u idle < /proc/uptime
|
read u idle < /proc/uptime
|
||||||
u=${u%.*}
|
u=${u%.*}
|
||||||
|
elif [ $(uname) = "FreeBSD" ]; then
|
||||||
|
u=$( sysctl -n kern.boottime | sed -En 's:.*sec = ([[:digit:]]+),.*:\1:p' )
|
||||||
|
u=$(($(date +%s) - $u))
|
||||||
elif [ -x /usr/sbin/sysctl ]; then
|
elif [ -x /usr/sbin/sysctl ]; then
|
||||||
# MacOS support
|
# MacOS support
|
||||||
u=$(/usr/sbin/sysctl -n kern.boottime | cut -f4 -d' ' | cut -d',' -f1)
|
u=$(/usr/sbin/sysctl -n kern.boottime | cut -f4 -d' ' | cut -d',' -f1)
|
||||||
|
@ -51,6 +54,4 @@ __uptime() {
|
||||||
fi
|
fi
|
||||||
[ -n "$str" ] || return
|
[ -n "$str" ] || return
|
||||||
color w b; printf "%s" "${str}"; color --
|
color w b; printf "%s" "${str}"; color --
|
||||||
}
|
}
|
||||||
|
|
||||||
# vi: syntax=sh ts=4 noexpandtab
|
|
Loading…
Add table
Add a link
Reference in a new issue