Chris's Wiki :: blog/linux/SeeingNetworkBandwidth Commentshttps://utcc.utoronto.ca/~cks/space/blog/linux/SeeingNetworkBandwidth?atomcommentsDWiki2008-05-12T12:21:48ZRecent comments in Chris's Wiki :: blog/linux/SeeingNetworkBandwidth.By Chris Siebenmann on /blog/linux/SeeingNetworkBandwidthtag:CSpace:blog/linux/SeeingNetworkBandwidth:ed1eafb9a297e550f5772db9b5ac017ba4b4b1f0Chris Siebenmann<div class="wikitext"><p>The really annoying thing about <code>/proc/net/dev</code> is that it sometimes has a
space between the : and the received byte count and sometimes doesn't
(if the byte count is big enough). Since the space is sometimes there, it
might be possible to persuade Linux people that it should always be there,
but I suspect it's unlikely since it hasn't been fixed before now.</p>
</div>2008-05-12T12:21:48ZFrom 71.121.1.227 on /blog/linux/SeeingNetworkBandwidthtag:CSpace:blog/linux/SeeingNetworkBandwidth:7bc164fb45869c6061cffe6f39ce63ce8349860bFrom 71.121.1.227<div class="wikitext"><p>The issue in this case is that the format of the /proc/net/dev is not very friendly for anything. Your original solution used sed just to remove the dev name (and the colon). You could have used awk to do the work as well,</p>
<pre>
getrxtx() {
awk "/$1:/"' {sub(".*:","",$1); print $1,$9;}' /proc/net/dev
}
</pre>
<p>I am assuming that as you dislike changing IFS, you would also not want to change awk's FS variable.</p>
<p>If on the other hand /proc/net/dev put a space after the : or else replaced the : with some whitespace then you would not need the 'sub' statement (just add 1 to the 1 and 9 to account for the extra field). It would also allow you not to need 'tricks' with IFS to split the line in my other solution. Of course it is now far too late to change the format of the file, so one has to work around the (lack of) design.</p>
<p>Icarus Sparry</p>
</div>2008-05-12T05:34:17ZFrom 168.103.159.247 on /blog/linux/SeeingNetworkBandwidthtag:CSpace:blog/linux/SeeingNetworkBandwidth:75c797bd826405102ef028ac747f9fc02543dbdbFrom 168.103.159.247<div class="wikitext"><p>I think iftop (<a href="http://www.ex-parrot.com/~pdw/iftop/">http://www.ex-parrot.com/~pdw/iftop/</a>) hits the sweet spot for this, much like top for basic load figures. The bpf and regex filtering bits are a nice bonus.</p>
</div>2008-05-12T05:10:43ZBy Chris Siebenmann on /blog/linux/SeeingNetworkBandwidthtag:CSpace:blog/linux/SeeingNetworkBandwidth:f46a717671734ba00201ad51dab3d6c19aa8711dChris Siebenmann<div class="wikitext"><p>I stand corrected about bash's array variables being (not) useful for this
sort of thing; evidently I didn't test them carefully enough. Personally,
I have never warmed to tricks with <code>$IFS</code>, and so don't use it even when
it might help.</p>
</div>2008-05-12T02:28:37ZFrom 71.121.1.227 on /blog/linux/SeeingNetworkBandwidthtag:CSpace:blog/linux/SeeingNetworkBandwidth:a1a535383b59ee8c3cc6d53d97c5dc266cc0bca4From 71.121.1.227<div class="wikitext"><p>Come on Chris, a grep followed by a sed followed by an awk? I am sure you could have thrown in a cat or two!</p>
<pre>
gettxrx(){
local IFS=$' \t\n:' A
A=($(grep "$1:" /proc/net/dev))
echo ${A[2]} ${A[10]}
}
</pre>
<p>And you could have used the more cryptic</p>
<pre>
IVAL=${2:-5}
</pre>
<p>Switching to ksh would have given you floating point, and you could have written the whole script using only builtins.</p>
<p>Icarus Sparry</p>
</div>2008-05-12T01:01:50ZBy Chris Siebenmann on /blog/linux/SeeingNetworkBandwidthtag:CSpace:blog/linux/SeeingNetworkBandwidth:9f122e98f1ffd91ffa20b2c08ac9e6969abb02e5Chris Siebenmann<div class="wikitext"><p>Dstat is interesting; thank you for the pointer.</p>
<p>Unfortunately I have to dock iptraf style points for requiring me to be
root to get anything out of it. I'm sure there's features that need root
access, but I want to get at least the unprivileged statistics (what I'm
usually interested in) without having to become root.</p>
</div>2008-05-09T19:24:21ZFrom 198.236.64.24 on /blog/linux/SeeingNetworkBandwidthtag:CSpace:blog/linux/SeeingNetworkBandwidth:358357a538aa5731220107f8470dc3a29f94d910From 198.236.64.24<div class="wikitext"><p>Not that I can't appreciate a good shell script, but iptraf is available in RHEL5. Cheers!</p>
<p>--
Dan Young</p>
</div>2008-05-09T15:11:28ZFrom 88.97.233.154 on /blog/linux/SeeingNetworkBandwidthtag:CSpace:blog/linux/SeeingNetworkBandwidth:c19d1e6647489279bb7cc53e4fca33e4d1162fdfFrom 88.97.233.154<div class="wikitext"><p>Useful, thanks.</p>
<p>Although not necessarily so portable; <a href="http://dag.wieers.com/home-made/dstat"><em>Dstat</em></a> is also a very handy tool to have around for measuring IO on Unix NAS and SAN hosts.</p>
</div>2008-05-09T08:08:20Z