#!/bin/bash # ====================================================================== # # Check NETIO to show traffic over all network cards # data besed on /proc/net/dev # # ---------------------------------------------------------------------- # 2020-07-08 v1.0 <axel.hahn@iml.unibe.ch> # ====================================================================== . `dirname $0`/inc_pluginfunctions # ---------------------------------------------------------------------- # MAIN # ---------------------------------------------------------------------- tmpfile1=`mktemp` tmpfile2=`mktemp` typeset -i iRead=0 typeset -i iTrans=0 typeset -i iSpeedRead=0 typeset -i iSpeedTrans=0 typeset -i iTotalRead=0 typeset -i iTotalTrans=0 cat /proc/net/dev | grep -E "(eth|en[ops][0-9]*)" >$tmpfile1 for myinterface in `cat $tmpfile1 | cut -f 1 -d ":" | tr -d " "` do echo >>$tmpfile2 echo "--- $myinterface" >> $tmpfile2 line=`grep "${myinterface}\:" $tmpfile1` # echo "SOURCE: $line" >> $tmpfile2 # total value of byte iRead=`echo $line | awk '{ print $2 }'` iTrans=`echo $line | awk '{ print $10 }'` # speed in byte per sec based on last stored value and its age iSpeedRead=` ph.perfdeltaspeed "netio-${myinterface}-rx" $iRead` iSpeedTrans=`ph.perfdeltaspeed "netio-${myinterface}-tx" $iTrans` # echo " > receive : $iRead .. $iSpeedRead byte/s" >> $tmpfile2 # echo " > transmit: $iTrans .. $iSpeedTrans byte/s" >> $tmpfile2 printf "%15s %15s %10s %-10s \n" "receive:" $iRead $iSpeedRead "byte/s" >> $tmpfile2 printf "%15s %15s %10s %-10s \n" "transmit:" $iTrans $iSpeedTrans "byte/s" >> $tmpfile2 # to store data for each interface # mylabel=`echo $line | awk '{ print $1 }' | tr [:upper:] [:lower:]` # ph.perfadd "${myinterface}-rx" "$iSpeedRead" # ph.perfadd "${myinterface}-tx" "$iSpeedTrans" iTotalRead=$iTotalRead+$iSpeedRead iTotalTrans=$iTotalTrans+$iSpeedTrans done echo "" >> $tmpfile2 echo "--- total:" >> $tmpfile2 # echo " > receive : $iTotalRead byte/s" >> $tmpfile2 # echo " > transmit: $iTotalTrans byte/s" >> $tmpfile2 printf "%15s %10s %-10s \n" "receive:" $iTotalRead "byte/s" >> $tmpfile2 printf "%15s %10s %-10s \n" "transmit:" $iTotalTrans "byte/s" >> $tmpfile2 ph.perfadd "rx" "$iTotalRead" ph.perfadd "tx" "$iTotalTrans" ph.status "Network IO ... IN `ph.toUnit $iTotalRead M` MB/s >> [host] >> `ph.toUnit $iTotalTrans M` MB/s OUT" # cat $tmpfile1 cat $tmpfile2 rm -f $tmpfile1 $tmpfile2 ph.exit