mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-21 14:03:18 -07:00
Merge 05a8d33b01
into bfb7a763d0
This commit is contained in:
commit
f440021855
8 changed files with 64 additions and 22 deletions
|
@ -25,7 +25,9 @@ __cpu_count_detail() {
|
||||||
|
|
||||||
__cpu_count() {
|
__cpu_count() {
|
||||||
local c
|
local c
|
||||||
c=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo)
|
c=$(getconf _NPROCESSORS_ONLN 2>/dev/null || \
|
||||||
|
grep -ci "^processor" /proc/cpuinfo || \
|
||||||
|
sysctl -n hw.ncpu)
|
||||||
[ "$c" = "1" ] || printf "%sx" "$c"
|
[ "$c" = "1" ] || printf "%sx" "$c"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ __cpu_freq_detail() {
|
||||||
|
|
||||||
__cpu_freq() {
|
__cpu_freq() {
|
||||||
local hz freq count
|
local hz freq count
|
||||||
|
|
||||||
if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" ]; then
|
if [ -r "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" ]; then
|
||||||
read hz < /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
|
read hz < /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
|
||||||
fpdiv $hz "1000000" 1 # 1Ghz
|
fpdiv $hz "1000000" 1 # 1Ghz
|
||||||
|
@ -33,7 +34,6 @@ __cpu_freq() {
|
||||||
if egrep -q -s -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo; then
|
if egrep -q -s -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo; then
|
||||||
freq=$(egrep -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo | awk -F"[:.]" '{ printf "%01.1f", $2 / 1000 }')
|
freq=$(egrep -i -m 1 "^cpu MHz|^clock" /proc/cpuinfo | awk -F"[:.]" '{ printf "%01.1f", $2 / 1000 }')
|
||||||
else
|
else
|
||||||
# Must scale frequency by number of processors, if counting bogomips
|
|
||||||
count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo)
|
count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || grep -ci "^processor" /proc/cpuinfo)
|
||||||
freq=$(egrep -i -m 1 "^bogomips" /proc/cpuinfo | awk -F"[:.]" '{ print $2 }')
|
freq=$(egrep -i -m 1 "^bogomips" /proc/cpuinfo | awk -F"[:.]" '{ print $2 }')
|
||||||
freq=$(printf "%s %s" "$freq" "$count" | awk '{printf "%01.1f\n", $1/$2/1000}')
|
freq=$(printf "%s %s" "$freq" "$count" | awk '{printf "%01.1f\n", $1/$2/1000}')
|
||||||
|
@ -41,7 +41,11 @@ __cpu_freq() {
|
||||||
elif hz=$(sysctl -n hw.cpufrequency 2>/dev/null); then
|
elif hz=$(sysctl -n hw.cpufrequency 2>/dev/null); then
|
||||||
fpdiv $hz "1000000000" 1 # 1Ghz
|
fpdiv $hz "1000000000" 1 # 1Ghz
|
||||||
freq="$_RET"
|
freq="$_RET"
|
||||||
|
elif hz=$(sysctl -n machdep.tsc_freq 2>/dev/null); then
|
||||||
|
fpdiv $hz "1000000000" 1
|
||||||
|
freq="$_RET"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ -n "$freq" ] || return
|
[ -n "$freq" ] || return
|
||||||
color b c W; printf "%s" "$freq"; color -; color c W; printf "%s" "$ICON_GHz"; color --
|
color b c W; printf "%s" "$freq"; color -; color c W; printf "%s" "$ICON_GHz"; color --
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,11 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
__disk_detail() {
|
__disk_detail() {
|
||||||
|
if [ $(uname) = "FreeBSD" ]; then
|
||||||
|
df -h
|
||||||
|
else
|
||||||
df -h -P
|
df -h -P
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
__disk() {
|
__disk() {
|
||||||
|
@ -32,7 +36,11 @@ __disk() {
|
||||||
esac
|
esac
|
||||||
# this could be done faster with 'stat --file-system --format'
|
# this could be done faster with 'stat --file-system --format'
|
||||||
# but then we'd have to do blocks -> human units ourselves
|
# but then we'd have to do blocks -> human units ourselves
|
||||||
|
if [ $(uname) = "FreeBSD" ]; then
|
||||||
|
out=$({ df -h "$MP" 2>/dev/null || df -h "$MP"; } | awk 'END { printf("%s %s", $2, $5); }')
|
||||||
|
else
|
||||||
out=$({ df -h -P "$MP" 2>/dev/null || df -h "$MP"; } | awk 'END { printf("%s %s", $2, $5); }')
|
out=$({ df -h -P "$MP" 2>/dev/null || df -h "$MP"; } | awk 'END { printf("%s %s", $2, $5); }')
|
||||||
|
fi
|
||||||
set -- ${out}
|
set -- ${out}
|
||||||
size=${1}; pct=${2};
|
size=${1}; pct=${2};
|
||||||
unit=${size#${size%?}} # get the unit (last char)
|
unit=${size#${size%?}} # get the unit (last char)
|
||||||
|
|
|
@ -26,6 +26,8 @@ __load_average_detail() {
|
||||||
__load_average() {
|
__load_average() {
|
||||||
if [ -r "/proc/loadavg" ]; then
|
if [ -r "/proc/loadavg" ]; then
|
||||||
read one five fifteen other < /proc/loadavg
|
read one five fifteen other < /proc/loadavg
|
||||||
|
elif [ $(uname) = "FreeBSD" ]; then
|
||||||
|
one=$(uptime | sed -En 's:.*averages\: ([[:digit:]]+\.[[:digit:]]+),.*:\1:p')
|
||||||
else
|
else
|
||||||
one=$(uptime | sed -e "s/.*://" | awk '{print $1}')
|
one=$(uptime | sed -e "s/.*://" | awk '{print $1}')
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -26,6 +26,8 @@ __memory_detail() {
|
||||||
__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 [ -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
|
||||||
|
@ -36,6 +38,23 @@ __memory() {
|
||||||
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
|
||||||
|
elif [ $(uname) = "FreeBSD" ]; then
|
||||||
|
# FreeBSD support
|
||||||
|
mem_phys=$(sysctl -n hw.physmem)
|
||||||
|
page_size=$(sysctl -n hw.pagesize)
|
||||||
|
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_free=$(($(sysctl -n vm.stats.vm.v_free_count)*$page_size))
|
||||||
|
|
||||||
|
mem_avail=$(($mem_inactive+$mem_cache+$mem_free))
|
||||||
|
mem_used=$(($mem_phys-$mem_avail))
|
||||||
|
|
||||||
|
total=$(($mem_phys/1024))
|
||||||
|
free=$(($mem_avail/1024))
|
||||||
|
|
||||||
|
buffers=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
|
||||||
|
@ -44,16 +63,18 @@ __memory() {
|
||||||
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}
|
||||||
|
|
|
@ -172,3 +172,5 @@ fi
|
||||||
color k w
|
color k w
|
||||||
printf "%s" "$display_time"
|
printf "%s" "$display_time"
|
||||||
color --
|
color --
|
||||||
|
|
||||||
|
# vi: syntax=sh ts=4 noexpandtab
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue