Skip to content
Snippets Groups Projects
Commit b528add1 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

netio: small fixes

parent fdeea247
No related branches found
No related tags found
1 merge request!134netio: small fixes
...@@ -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,17 +75,19 @@ typeset -i iTotalTrans=0 ...@@ -76,17 +75,19 @@ 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" )
out=$(
for myinterface in $sInterface for myinterface in $sInterface
do do
echo >>"$tmpfile2" echo
echo "--- ${myinterface}:" >> "$tmpfile2" echo "--- ${myinterface}:"
line=$( grep "${myinterface}:" <<< "$data" ) line=$( grep "${myinterface}:" <<< "$data" )
if [ -n "$line" ] ; then 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 }')
...@@ -96,40 +97,39 @@ do ...@@ -96,40 +97,39 @@ do
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 done
echo
)
echo "" >> "$tmpfile2" # ----- total
if [ $iCountInterfaces -gt 1 ]; then if [ $iCountInterfaces -gt 1 ]; then
out+=$(
echo "--- total:" echo "--- total:"
printf "%15s %10s %-10s \n" "receive:" $iTotalRead "byte/s" printf "%15s %10s %-10s \n" "receive:" $iTotalRead "byte/s"
printf "%15s %10s %-10s \n" "transmit:" $iTotalTrans "byte/s" printf "%15s %10s %-10s \n" "transmit:" $iTotalTrans "byte/s"
fi >> "$tmpfile2" )
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment