Skip to content
Snippets Groups Projects

netio: small fixes

Merged Hahn Axel (hahn) requested to merge 6468-docs-and-harmonize into master
1 file
+ 39
39
Compare changes
  • Side-by-side
  • Inline
+ 39
39
@@ -7,12 +7,13 @@
@@ -7,12 +7,13 @@
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# 2020-07-08 v1.0 <axel.hahn@iml.unibe.ch>
# 2020-07-08 v1.0 <axel.hahn@iml.unibe.ch>
# 2023-08-21 v1.1 <axel.hahn@unibe.ch> add help; add param -i
# 2023-08-21 v1.1 <axel.hahn@unibe.ch> add help; add param -i
 
# 2023-08-22 v1.2 <axel.hahn@unibe.ch> send perf data on single interface too; interfaces in alphabetic order; no more tmp file
# ======================================================================
# ======================================================================
. $( dirname $0 )/inc_pluginfunctions
. $( dirname $0 )/inc_pluginfunctions
export self_APPVERSION=1.1
export self_APPVERSION=1.2
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
@@ -62,8 +63,6 @@ if [ $bOptHelp -eq 1 ]; then
@@ -62,8 +63,6 @@ if [ $bOptHelp -eq 1 ]; then
exit 0
exit 0
fi
fi
tmpfile2=`mktemp`
typeset -i iCountInterfaces
typeset -i iCountInterfaces
typeset -i iRead=0
typeset -i iRead=0
@@ -76,60 +75,61 @@ typeset -i iTotalTrans=0
@@ -76,60 +75,61 @@ typeset -i iTotalTrans=0
data=$( cat /proc/net/dev | grep -E "(eth|en[ops][0-9]*)" )
data=$( cat /proc/net/dev | grep -E "(eth|en[ops][0-9]*)" )
allInterfaces=$( cut -f 1 -d ":" <<< "$data" | tr -d " " )
allInterfaces=$( cut -f 1 -d ":" <<< "$data" | tr -d " " )
sInterface=$( ph.getValueWithParam "$allInterfaces" "i" "$@")
sInterface=$( ph.getValueWithParam "$allInterfaces" "i" "$@" | sort )
 
# ----- loop over all interfaces
iCountInterfaces=$( wc -w <<< "$sInterface" )
iCountInterfaces=$( wc -w <<< "$sInterface" )
for myinterface in $sInterface
out=$(
do
for myinterface in $sInterface
echo >>"$tmpfile2"
do
echo "--- ${myinterface}:" >> "$tmpfile2"
echo
line=$( grep "${myinterface}:" <<< "$data" )
echo "--- ${myinterface}:"
if [ -n "$line" ] ; then
line=$( grep "${myinterface}:" <<< "$data" )
 
if [ -n "$line" ] ; then
# echo "SOURCE: $line" >> $tmpfile2
# echo "SOURCE: $line"
# total value of byte
# total value of byte
iRead=$( echo "$line" | awk '{ print $2 }')
iRead=$( echo "$line" | awk '{ print $2 }')
iTrans=$(echo "$line" | awk '{ print $10 }')
iTrans=$(echo "$line" | awk '{ print $10 }')
# speed in byte per sec based on last stored value and its age
# speed in byte per sec based on last stored value and its age
iSpeedRead=$( ph.perfdeltaspeed "netio-${myinterface}-rx" $iRead)
iSpeedRead=$( ph.perfdeltaspeed "netio-${myinterface}-rx" $iRead)
iSpeedTrans=$(ph.perfdeltaspeed "netio-${myinterface}-tx" $iTrans)
iSpeedTrans=$(ph.perfdeltaspeed "netio-${myinterface}-tx" $iTrans)
printf "%15s %15s %10s %-10s \n" "receive:" $iRead $iSpeedRead "byte/s" >> "$tmpfile2"
printf "%15s %15s %10s %-10s \n" "receive:" $iRead $iSpeedRead "byte/s"
printf "%15s %15s %10s %-10s \n" "transmit:" $iTrans $iSpeedTrans "byte/s" >> "$tmpfile2"
printf "%15s %15s %10s %-10s \n" "transmit:" $iTrans $iSpeedTrans "byte/s"
# to store data for each interface
if [ $iCountInterfaces -gt 1 ]; then
ph.perfadd "rx-${myinterface}" "$iSpeedRead"
ph.perfadd "rx-${myinterface}" "$iSpeedRead"
ph.perfadd "tx-${myinterface}" "$iSpeedTrans"
ph.perfadd "tx-${myinterface}" "$iSpeedTrans"
fi
iTotalRead=$iTotalRead+$iSpeedRead
iTotalRead=$iTotalRead+$iSpeedRead
iTotalTrans=$iTotalTrans+$iSpeedTrans
iTotalTrans=$iTotalTrans+$iSpeedTrans
else
else
ph.setStatus "unknown"
ph.setStatus "unknown"
echo "UNKNOWN: the interface ${myinterface} does not exist." >> "$tmpfile2"
echo "The interface [${myinterface}] does not exist."
fi
fi
done
echo "" >> "$tmpfile2"
done
 
echo
 
)
 
# ----- total
if [ $iCountInterfaces -gt 1 ]; then
if [ $iCountInterfaces -gt 1 ]; then
echo "--- total:"
printf "%15s %10s %-10s \n" "receive:" $iTotalRead "byte/s"
printf "%15s %10s %-10s \n" "transmit:" $iTotalTrans "byte/s"
fi >> "$tmpfile2"
 
out+=$(
 
echo "--- total:"
 
printf "%15s %10s %-10s \n" "receive:" $iTotalRead "byte/s"
 
printf "%15s %10s %-10s \n" "transmit:" $iTotalTrans "byte/s"
 
)
 
 
fi
ph.perfadd "rx" "$iTotalRead"
ph.perfadd "rx" "$iTotalRead"
ph.perfadd "tx" "$iTotalTrans"
ph.perfadd "tx" "$iTotalTrans"
 
# ----- output
ph.status "Network IO ... IN $(ph.toUnit $iTotalRead M) MB/s >> [host] >> $(ph.toUnit $iTotalTrans M) MB/s OUT"
ph.status "Network IO ... IN $(ph.toUnit $iTotalRead M) MB/s >> [host] >> $(ph.toUnit $iTotalTrans M) MB/s OUT"
cat "$tmpfile2"
echo "$out"
rm -f "$tmpfile2"
ph.exit
ph.exit
Loading