From 6c8627c1f7fdb63dbef22f4909a7c69830bdca6d Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Mon, 26 Apr 2010 14:07:01 -0500 Subject: [PATCH] * bin/byobu-config, lib/byobu/disk_io, share/byobu/profiles/common, share/man/man1/byobu.1: added a disk throughput notification * usr/bin/byobu-janitor: add hyphenation to the regex to allow for disk_io --- debian/changelog | 6 ++- etc/byobu/statusrc | 1 + usr/bin/byobu-config | 1 + usr/bin/byobu-janitor | 4 +- usr/lib/byobu/disk_io | 66 +++++++++++++++++++++++++++++++++ usr/share/byobu/profiles/common | 3 +- usr/share/man/man1/byobu.1 | 4 +- 7 files changed, 80 insertions(+), 5 deletions(-) create mode 100755 usr/lib/byobu/disk_io diff --git a/debian/changelog b/debian/changelog index bd735889..77134fbf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,10 +1,14 @@ -byobu (2.72) unreleased; urgency=low +byobu (2.72-0ubuntu1) maverick; urgency=low * usr/bin/byobu: support nethack screen mode, LP: #568751 * usr/share/man/man1/byobu.1: document a sample custom script using custom colors, LP: #568967 * usr/bin/byobu: LANG=C before grepping for text * usr/bin/byobu: handle unset term in tput 256 color check + * bin/byobu-config, lib/byobu/disk_io, share/byobu/profiles/common, + share/man/man1/byobu.1: added a disk throughput notification + * usr/bin/byobu-janitor: add hyphenation to the regex to allow for + disk_io -- Dustin Kirkland Thu, 22 Apr 2010 12:31:20 -0500 diff --git a/etc/byobu/statusrc b/etc/byobu/statusrc index 86c73f28..720225a4 100644 --- a/etc/byobu/statusrc +++ b/etc/byobu/statusrc @@ -29,6 +29,7 @@ cpu_temp=0 custom=1 date=1 disk=0 +disk_io=0 ec2_cost=0 fan_speed=0 hostname=1 diff --git a/usr/bin/byobu-config b/usr/bin/byobu-config index 7dc68bed..930f74d9 100755 --- a/usr/bin/byobu-config +++ b/usr/bin/byobu-config @@ -289,6 +289,7 @@ def readstatus(): status["custom"]=1 status["date"]=1 status["disk"]=0 + status["disk_io"]=0 status["ec2_cost"]=0 status["fan_speed"]=0 status["hostname"]=1 diff --git a/usr/bin/byobu-janitor b/usr/bin/byobu-janitor index 71b0f304..618b174b 100755 --- a/usr/bin/byobu-janitor +++ b/usr/bin/byobu-janitor @@ -96,8 +96,8 @@ fi # underscores such that we can source the file as a shell snippet; # fix existing status configuration. sed -i "s/\(.*\)-\(.*\)=/\1_\2=/g" "$HOME/.$PKG/status" -sed -i "s/^disk.*=/disk=/" "$HOME/.$PKG/status" -sed -i "s/^network.*=/network=/" "$HOME/.$PKG/status" +sed -i "s/^disk-.*=/disk=/" "$HOME/.$PKG/status" +sed -i "s/^network-.*=/network=/" "$HOME/.$PKG/status" # Affects: Upgrades from <= byobu-2.16 # screen-launcher was renamed byobu-launcher; if the user has byobu diff --git a/usr/lib/byobu/disk_io b/usr/lib/byobu/disk_io new file mode 100755 index 00000000..55734ac3 --- /dev/null +++ b/usr/lib/byobu/disk_io @@ -0,0 +1,66 @@ +#!/bin/sh -e +# +# disk_io: calculate the disk io rate +# Copyright (C) 2010 Canonical Ltd. +# +# Authors: Dustin Kirkland +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +PKG="byobu" +color 2>/dev/null || color() { true; } + +# Allow interface overrides in $HOME/.$PKG/status +if [ -n "$MONITORED_DISK" ]; then + disk="$MONITORED_DISK" +else + disk=$(df -h / | tail -n1 | sed -e "s/[0-9].*$//" -e "s:^.*/::") +fi + +if [ "$1" = "--detail" ]; then + if [ -x /usr/bin/iostat ]; then + iostat -d -m -h + else + echo "Please install iostat if you want detailed information on your disk throughput" + fi + exit 0 +fi + +[ -d "/var/run/screen/S-$USER" ] && DIR="/var/run/screen/S-$USER" || DIR="$HOME/.byobu" +t2=`date +%s` +for i in "read" "write"; do + cache="$DIR/$PKG.disk_$i" + t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0 + unit="kB/s" + if [ $t2 -le $t1 ]; then + rate=0 + else + x1=`cat "$cache"` 2>/dev/null || tx1=0 + if [ "$i" = "read" ]; then + symbol="<" + x2=`awk '{print $3}' /sys/block/$disk/stat` + else + symbol=">" + x2=`awk '{print $7}' /sys/block/$disk/stat` + fi + echo "$x2" > "$cache" + rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) * 512 / 1024 }'` + if [ "$rate" -lt 0 ]; then + rate=0 + elif [ "$rate" -gt 1024 ]; then + rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'` + unit="MB/s" + fi + fi + printf "$symbol$(color b M W)$rate$(color -)$(color M W)$unit$(color -) " +done diff --git a/usr/share/byobu/profiles/common b/usr/share/byobu/profiles/common index f4fd9579..7f30fbeb 100644 --- a/usr/share/byobu/profiles/common +++ b/usr/share/byobu/profiles/common @@ -70,6 +70,7 @@ backtick 129 67 67 byobu-status apport backtick 130 5 5 byobu-status custom backtick 131 53 53 byobu-status services backtick 132 11 11 byobu-status time_utc +backtick 133 3 3 byobu-status disk_io hardstatus alwayslastline @@ -103,7 +104,7 @@ source $HOME/.byobu/keybindings caption always "%12`%?%-Lw%50L>%?%{=r}%n*%f %t%?(%u)%?%{-}%12`%?%+Lw%?%11` %=%12`%110`%109`%122`%111`%10`%<" # Status string, last line -hardstatus string '%99`%{-}%{=r}%12` %100`%112`%= %130`%102`%101`%129`%131`%127`%114`%115`%108`%128`%125`%126`%113`%119`%117`%116`%106`%104`%103`%105`%107`%123`%132`%120`%121`' +hardstatus string '%99`%{-}%{=r}%12` %100`%112`%= %130`%102`%101`%129`%131`%127`%114`%115`%108`%128`%125`%126`%113`%119`%133`%117`%116`%106`%104`%103`%105`%107`%123`%132`%120`%121`' # NOTE: Older version of screen have an arbitrary limit of only being able # to change colors 16 times in this 'hardstatus string'. diff --git a/usr/share/man/man1/byobu.1 b/usr/share/man/man1/byobu.1 index dc7901a4..98d77c56 100644 --- a/usr/share/man/man1/byobu.1 +++ b/usr/share/man/man1/byobu.1 @@ -32,6 +32,8 @@ byobu \- wrapper script for seeding a user's byobu configuration and launching s \fBdisk\fP \- total disk space available and total used on / directory; displayed in the lower bar on the far right in white text on a light purple background; override the default directory by specifying an alternate mount point with MONITORED_DISK=/wherever in \fI$HOME/.byobu/statusrc\fP +\fBdisk_io\fP \- instantaneous read/write througput in kB/s or MB/s over the last 3 seconds; displayed in the lower bar toward the right in white text on a light purple background with a leading '<' sign indicating 'read speed' and '>' sign indicating 'write speed'; override the default monitored disk by specifying an alternate device with MONITORED_disk=/dev/sdb in \fI$HOME/.byobu/statusrc\fP + \fBec2_cost\fP \- an estimation of the cost of the current boot of the system in terms of the Amazon EC2 billing model; displayed in the lower bar toward the right in green text on a black background; there is a leading '~' to indicate that this is an estimation, and the monetary units are US Dollars '$' \fBfan_speed\fP \- cpu or system fan speed as reported by lm-sensors; displayed in the lower bar toward the right in black text on a grey background; there is a trailing 'rpm' for units @@ -52,7 +54,7 @@ byobu \- wrapper script for seeding a user's byobu configuration and launching s \fBmenu\fP \- a simple indicator directing new users to use the F9 keybinding to access the byobu menu -\fBnetwork\fP \- instantaneous upload/download bandwidth in kB/s over the last 2 seconds; displayed in the lower bar toward the right in white text on a purple background with a leading '^' sign indicating 'up' and 'v' sign indicating 'down'; override the default interface by specifying an alternate interface with MONITORED_NETWORK=eth1 in \fI$HOME/.byobu/statusrc\fP +\fBnetwork\fP \- instantaneous upload/download bandwidth in kB/s over the last 3 seconds; displayed in the lower bar toward the right in white text on a purple background with a leading '^' sign indicating 'up' and 'v' sign indicating 'down'; override the default interface by specifying an alternate interface with MONITORED_NETWORK=eth1 in \fI$HOME/.byobu/statusrc\fP \fBprocesses\fP \- total number of processes running on the system; displayed in the lower bar in white text on a dark yellow background with a trailing '&' indicating 'background processes'