čtvrtek 22. května 2008

Simple Solaris iptraf like script

How to monitor interface throughput on Solaris machine? I was looking for some sort of Linux's IPtraf (which is a great ip traffic monitor which can show you more than just interface traffic throuput) for Solaris. Seems no IPtraf port or similar text utility for Solaris so far. The script below should help you a bit and show the interface throughput.

It only prints out througput of the interface in 5 second intervals. If your system's interface is named ce0 instead of hme0, you need to change the script 'hme:0:hme0:*bytes' to 'ce:0:ce0:*bytes'.

#!/usr/bin/bash
WAIT=5
# traffic monitor
# writes total number of bytes (traffic) per interval

I_BYTES_OLD=`kstat -p 'hme:0:hme0:*bytes' | grep rbytes | awk -F" " '{ print $2}'`
O_BYTES_OLD=`kstat -p 'hme:0:hme0:*bytes' | grep obytes | awk -F" " '{ print $2}'`

while true
do
DATE=`date +%m/%d/%y" "%H:%M:%S`

I_BYTES=`kstat -p 'hme:0:hme0:*bytes' | grep rbytes | awk -F" " '{ print $2}'`
O_BYTES=`kstat -p 'hme:0:hme0:*bytes' | grep obytes | awk -F" " '{ print $2}'`

I_BYTES_DIFF=`echo $I_BYTES - $I_BYTES_OLD | bc`
O_BYTES_DIFF=`echo $O_BYTES - $O_BYTES_OLD | bc`

I_BYTES_OLD=$I_BYTES
O_BYTES_OLD=$O_BYTES

T_BYTES=`echo $I_BYTES_DIFF + $O_BYTES_DIFF | bc`

sleep $WAIT
clear
echo "$DATE interface: hme0 input: $I_BYTES_DIFF output: $O_BYTES_DIFF totalBytes: $T
_BYTES"
done

Žádné komentáře: