Getting live network bandwidth numbers on Solaris
After I wrote netvolmon for Linux,
I started getting curious about how much bandwidth our current Solaris
NFS servers were using. Unfortunately, Solaris's version of ifconfig
does not report byte counts; fortunately, the kernel does keep this
information and you can dig it out with kstat
(information courtesy
of here, which has a
bunch of more sophisticated programs to report on this stuff).
The magic kstat
incantation is 'kstat -p "*:*:<DEV>:*bytes64"
',
which gets you the obytes64 and rbytes64 counters for the device; this
works on at least Solaris 8 and Solaris 10. (In this Solaris does Linux
one better, since a 32-bit Linux machines use 32-bit network counters
and on a saturated gigabit link they can roll over in under 20 seconds.)
Armed with this we can write the obvious Solaris version of netvolmon
:
#!/bin/sh # usage: netvolmon DEV [INTERVAL] DEV=$1 IVAL=${2:-5} getrxtx() { kstat -p "*:*:$1:*bytes64" | awk '{print $2}' } rxtx=`getrxtx $DEV` while sleep $IVAL; do nrxtx=`getrxtx $DEV` (echo $IVAL $rxtx $nrxtx) | awk 'BEGIN { msg = "%6.2f MB/s RX %6.2f MB/s TX\n"} {rxd = ($4 - $2) / (1024*1024*$1); txd = ($5 - $3) / (1024*1024*$1); printf msg, rxd, txd}' rxtx="$nrxtx" done
Vaguely to my surprise, it turns out that Solaris 8 awk doesn't allow
you to split printf
(and presumably print
) statements over multiple
lines. The Solaris shell is backwards and doesn't support the POSIX
shell $(...)
syntax, even in Solaris 10, so this version uses the less
pleasant backquote syntax.
(This can easily be extended to report packets per second as well; the device counters you want are 'opackets64' and 'rpackets64'. I didn't put it in this version for a petty reason, namely that it would make this entry too wide, but you can get the full versions for both Solaris and Linux here.)
Comments on this page:
|
|