17
19
# You should have received a copy of the GNU General Public License
18
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
color 2>/dev/null || color() { true; }
23
# Default to disk providing /, but let users override with MONITORED_DISK
24
[ -z "$MONITORED_DISK" ] && MP="/" || MP="$MONITORED_DISK"
27
*) disk=$(grep -m 1 " $MP " /etc/mtab | sed -e "s: .*$::") ;;
29
disk=$(echo "$disk" | sed -e "s: .*$::" -e "s:^.*/::" -e "s:\([hsv]d[a-z]\)[0-9]*$:\1:")
31
if [ "$1" = "--detail" ]; then
32
if which iostat >/dev/null; then
23
if command -v iostat >/dev/null; then
35
26
echo "Please install iostat if you want detailed information on your disk throughput"
40
[ -d "/var/run/screen/S-$USER" ] && DIR="/var/run/screen/S-$USER" || DIR="$HOME/.byobu"
42
for i in "read" "write"; do
43
cache="$DIR/$PKG.disk_$i"
44
t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0
46
if [ $t2 -le $t1 ]; then
33
if [ -L "${1}" ]; then
34
t=$($READLINK -f "$1")
49
x1=`cat "$cache"` 2>/dev/null || tx1=0
50
if [ "$i" = "read" ]; then
52
x2=`awk '{print $3}' /sys/block/$disk/stat`
39
[ -h "/sys/block/$t" ] && _RET="$t" || rtrim "$t" "0-9"
44
# Default to disk providing /, but let users override with MONITORED_DISK
45
[ -z "$MONITORED_DISK" ] && mount_point="/" || mount_point="$MONITORED_DISK"
46
# By default, we won't bug the user with the display of network traffic
47
# below DISK_IO_THRESHOLD in kB/s; override in $BYOBU_CONFIG_DIR/status
48
[ -n "$DISK_IO_THRESHOLD" ] || DISK_IO_THRESHOLD=50
49
case "$mount_point" in
50
/dev/*) part="${mount_point}";;
51
*) part=$(awk '$2 == mp { print $1 ; exit(0); }' "mp=$mount_point" /etc/mtab);;
55
local t2=`date +%s` t1=
56
for i in "read" "write"; do
57
local cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/disk.$i"
58
t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0
60
local rate= x1= x2= symbol= unit=
61
if [ $t2 -le $t1 ]; then
55
x2=`awk '{print $7}' /sys/block/$disk/stat`
58
rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) * 512 / 1024 }'`
59
if [ "$rate" -lt 0 ]; then
61
elif [ "$rate" -gt 1024 ]; then
62
rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'`
66
printf "$symbol$(color b M W)$rate$(color -)$(color M W)$unit$(color -) "
64
[ -r "$cache" ] && read x1 < "$cache" || x1=0
65
local a1= a2= a3= a4= a5= a6= a7= a8= a9= a10=
66
read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 other < "/sys/block/$disk/stat"
67
if [ "$i" = "read" ]; then
75
rate=$((($x2 - $x1) / ($t2 - $t1) * 512 / 1024))
76
if [ $rate -lt $DISK_IO_THRESHOLD ]; then
77
# Below threshold, don't print
79
elif [ "$rate" -lt 0 ]; then
81
elif [ "$rate" -gt 1048576 ]; then
83
fpdiv "$rate" 1048576 0
85
elif [ "$rate" -gt 1024 ]; then
93
[ "$rate" != "0" ] || continue
94
color b M W; printf "%s%s" "$symbol" "$rate"; color -; color M W; printf "%s" "$unit"; color --
98
# vi: syntax=sh ts=4 noexpandtab