mirror of
https://github.com/teddysun/across.git
synced 2025-01-19 06:19:35 +08:00
Improve disk usage calculation (#115)
1. use "free -k" to get swap usage 2. improve disk usage calculation to support ZFS
This commit is contained in:
parent
70f8bd140d
commit
5d975e90ef
32
bench.sh
32
bench.sh
@ -115,6 +115,22 @@ calc_size() {
|
|||||||
echo "${total_size} ${unit}"
|
echo "${total_size} ${unit}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# since calc_size converts kilobyte to MB, GB and TB
|
||||||
|
# to_kibyte converts zfs size from bytes to kilobyte
|
||||||
|
to_kibyte() {
|
||||||
|
local raw=$1
|
||||||
|
echo ${raw} / 1024
|
||||||
|
}
|
||||||
|
|
||||||
|
sum() {
|
||||||
|
local arr=("$@")
|
||||||
|
local s=0
|
||||||
|
for i in "${arr[@]}"; do
|
||||||
|
s=$(($s + $i))
|
||||||
|
done
|
||||||
|
echo ${s}
|
||||||
|
}
|
||||||
|
|
||||||
check_virt() {
|
check_virt() {
|
||||||
_exists "dmesg" && virtualx="$(dmesg 2>/dev/null)"
|
_exists "dmesg" && virtualx="$(dmesg 2>/dev/null)"
|
||||||
if _exists "dmidecode"; then
|
if _exists "dmidecode"; then
|
||||||
@ -280,16 +296,20 @@ get_system_info() {
|
|||||||
echo ${arch} | grep -q "64" && lbit="64" || lbit="32"
|
echo ${arch} | grep -q "64" && lbit="64" || lbit="32"
|
||||||
fi
|
fi
|
||||||
kern=$(uname -r)
|
kern=$(uname -r)
|
||||||
disk_total_size=$(
|
in_kernel_no_swap_total_size=$(
|
||||||
LANG=C
|
LANG=C
|
||||||
df -t simfs -t ext2 -t ext3 -t ext4 -t btrfs -t xfs -t vfat -t ntfs -t swap --total 2>/dev/null | grep total | awk '{ print $2 }'
|
df -t simfs -t ext2 -t ext3 -t ext4 -t btrfs -t xfs -t vfat -t ntfs --total 2>/dev/null | grep total | awk '{ print $2 }'
|
||||||
)
|
)
|
||||||
disk_total_size=$(calc_size $disk_total_size)
|
swap_total_size=$(free -k | grep Swap | awk '{print $2}')
|
||||||
disk_used_size=$(
|
zfs_total_size=$(to_kibyte $(sum $(zpool list -o size -Hp 2> /dev/null)))
|
||||||
|
disk_total_size=$(calc_size $(($swap_total_size + $in_kernel_no_swap_total_size + $zfs_total_size)))
|
||||||
|
in_kernel_no_swap_used_size=$(
|
||||||
LANG=C
|
LANG=C
|
||||||
df -t simfs -t ext2 -t ext3 -t ext4 -t btrfs -t xfs -t vfat -t ntfs -t swap --total 2>/dev/null | grep total | awk '{ print $3 }'
|
df -t simfs -t ext2 -t ext3 -t ext4 -t btrfs -t xfs -t vfat -t ntfs --total 2>/dev/null | grep total | awk '{ print $3 }'
|
||||||
)
|
)
|
||||||
disk_used_size=$(calc_size $disk_used_size)
|
swap_used_size=$(free -k | grep Swap | awk '{print $3}')
|
||||||
|
zfs_used_size=$(to_kibyte $(sum $(zpool list -o allocated -Hp 2> /dev/null)))
|
||||||
|
disk_used_size=$(calc_size $(($swap_used_size + $in_kernel_no_swap_used_size + $zfs_used_size)))
|
||||||
tcpctrl=$(sysctl net.ipv4.tcp_congestion_control | awk -F ' ' '{print $3}')
|
tcpctrl=$(sysctl net.ipv4.tcp_congestion_control | awk -F ' ' '{print $3}')
|
||||||
}
|
}
|
||||||
# Print System information
|
# Print System information
|
||||||
|
Loading…
x
Reference in New Issue
Block a user