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

Merge branch '6468-docs-and-harmonize' into 'master'

netio - add help; add param -i

See merge request !131
parents 2a962b0e 40a1685c
Branches
No related tags found
1 merge request!131netio - add help; add param -i
...@@ -6,19 +6,66 @@ ...@@ -6,19 +6,66 @@
# #
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# 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
# ====================================================================== # ======================================================================
. `dirname $0`/inc_pluginfunctions . $( dirname $0 )/inc_pluginfunctions
export self_APPVERSION=1.1
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
# show help text
function showHelp(){
local _self; _self=$(basename $0)
cat <<EOF
$( ph.showImlHelpHeader )
Show network io for all or selected interfaces.
It shows the current counter value from /proc/net/dev and the speed
in byte per sec since last execution.
This plugin sends performancedata.
SYNTAX:
$_self [-h] [-i INTERFACE(S)]
OPTIONS:
-h this help
PARAMETERS:
-i INTERFACE show this interface only. Quote multiple interfaces.
The check returns unknown if an interface does not
exist.
EXAMPLES:
$_self show netio of all network interfaces
$_self -i "eth0 eth1"
show netio of given interfaces.
EOF
}
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# MAIN # MAIN
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
bOptHelp=$( ph.hasParamoption "h" "$@")
if [ $bOptHelp -eq 1 ]; then
showHelp
exit 0
fi
tmpfile1=`mktemp`
tmpfile2=`mktemp` tmpfile2=`mktemp`
typeset -i iCountInterfaces
typeset -i iRead=0 typeset -i iRead=0
typeset -i iTrans=0 typeset -i iTrans=0
typeset -i iSpeedRead=0 typeset -i iSpeedRead=0
...@@ -26,54 +73,63 @@ typeset -i iSpeedTrans=0 ...@@ -26,54 +73,63 @@ typeset -i iSpeedTrans=0
typeset -i iTotalRead=0 typeset -i iTotalRead=0
typeset -i iTotalTrans=0 typeset -i iTotalTrans=0
cat /proc/net/dev | grep -E "(eth|en[ops][0-9]*)" >$tmpfile1 data=$( cat /proc/net/dev | grep -E "(eth|en[ops][0-9]*)" )
for myinterface in `cat $tmpfile1 | cut -f 1 -d ":" | tr -d " "` allInterfaces=$( cut -f 1 -d ":" <<< "$data" | tr -d " " )
sInterface=$( ph.getValueWithParam "$allInterfaces" "i" "$@")
iCountInterfaces=$( wc -w <<< "$sInterface" )
for myinterface in $sInterface
do do
echo >>$tmpfile2 echo >>"$tmpfile2"
echo "--- $myinterface" >> $tmpfile2 echo "--- ${myinterface}:" >> "$tmpfile2"
line=`grep "${myinterface}\:" $tmpfile1` line=$( grep "${myinterface}:" <<< "$data" )
if [ -n "$line" ] ; then
# echo "SOURCE: $line" >> $tmpfile2 # echo "SOURCE: $line" >> $tmpfile2
# 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)
# 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" "receive:" $iRead $iSpeedRead "byte/s" >> "$tmpfile2"
printf "%15s %15s %10s %-10s \n" "transmit:" $iTrans $iSpeedTrans "byte/s" >> $tmpfile2 printf "%15s %15s %10s %-10s \n" "transmit:" $iTrans $iSpeedTrans "byte/s" >> "$tmpfile2"
# to store data for each interface # to store data for each interface
# mylabel=`echo $line | awk '{ print $1 }' | tr [:upper:] [:lower:]` if [ $iCountInterfaces -gt 1 ]; then
# ph.perfadd "${myinterface}-rx" "$iSpeedRead" ph.perfadd "rx-${myinterface}" "$iSpeedRead"
# ph.perfadd "${myinterface}-tx" "$iSpeedTrans" ph.perfadd "tx-${myinterface}" "$iSpeedTrans"
fi
iTotalRead=$iTotalRead+$iSpeedRead iTotalRead=$iTotalRead+$iSpeedRead
iTotalTrans=$iTotalTrans+$iSpeedTrans iTotalTrans=$iTotalTrans+$iSpeedTrans
else
ph.setStatus "unknown"
echo "UNKNOWN: the interface ${myinterface} does not exist." >> "$tmpfile2"
fi
done done
echo "" >> $tmpfile2 echo "" >> "$tmpfile2"
echo "--- total:" >> $tmpfile2
# echo " > receive : $iTotalRead byte/s" >> $tmpfile2 if [ $iCountInterfaces -gt 1 ]; then
# echo " > transmit: $iTotalTrans byte/s" >> $tmpfile2 echo "--- total:"
printf "%15s %10s %-10s \n" "receive:" $iTotalRead "byte/s" >> $tmpfile2 printf "%15s %10s %-10s \n" "receive:" $iTotalRead "byte/s"
printf "%15s %10s %-10s \n" "transmit:" $iTotalTrans "byte/s" >> $tmpfile2 printf "%15s %10s %-10s \n" "transmit:" $iTotalTrans "byte/s"
fi >> "$tmpfile2"
ph.perfadd "rx" "$iTotalRead" ph.perfadd "rx" "$iTotalRead"
ph.perfadd "tx" "$iTotalTrans" ph.perfadd "tx" "$iTotalTrans"
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 $tmpfile1 cat "$tmpfile2"
cat $tmpfile2
rm -f $tmpfile1 $tmpfile2 rm -f "$tmpfile2"
ph.exit ph.exit
...@@ -26,7 +26,7 @@ There is one include script used by all checks: ...@@ -26,7 +26,7 @@ There is one include script used by all checks:
* [check_haproxy_status](check_haproxy_status.md) * [check_haproxy_status](check_haproxy_status.md)
* [check_memory](check_memory.md) * [check_memory](check_memory.md)
* [check_mysqlserver](check_mysqlserver.md) * [check_mysqlserver](check_mysqlserver.md)
* check_netio * [check_netio](check_netio.md)
* [check_netstat](check_netstat.md) * [check_netstat](check_netstat.md)
* [check_onehost](check_onehost.md) * [check_onehost](check_onehost.md)
* [check_onevm](check_onevm.md) * [check_onevm](check_onevm.md)
......
# check_netio
## Introduction
Show network io for all or selected interfaces.
This plugin scans `/proc/net/dev` with the regex `eth|en[ops][0-9]*` to show a few types of interfaces.
### Requirements
* none
## Syntax
```text
> ./check_netio -h
______________________________________________________________________
CHECK_NETIO
v1.1
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_netio.html
______________________________________________________________________
Show network io for all or selected interfaces.
It shows the current counter value from /proc/net/dev and the speed
in byte per sec since last execution.
This plugin sends performancedata.
SYNTAX:
check_netio [-h] [-i INTERFACE(S)]
OPTIONS:
-h this help
PARAMETERS:
-i INTERFACE show this interface only. Quote multiple interfaces.
The check returns unknown if an interface does not
exist.
EXAMPLES:
check_netio show netio of all network interfaces
check_netio -i "eth0 eth1"
show netio of given interfaces.
```
## Examples
### Host with single interface
A simple call on a host with a single interface... `check_netio` returns
```txt
OK: Network IO ... IN 0 MB/s >> [host] >> 0 MB/s OUT
--- enp0s31f6:
receive: 1079156830 28849 byte/s
transmit: 1082596810 2898 byte/s
|rx=28849;; tx=2898;;
```
### Custom interface
You get the same output with `check_netio -i enp0s31f6`.
If you enter a wrong interface the check returns with "UNKNOWN".
`check_netio -i "whatever"`returns
```txt
UNKNOWN: Network IO ... IN 0 MB/s >> [host] >> 0 MB/s OUT
--- whatever:
UNKNOWN: the interface whatever does not exist.
|rx=0;; tx=0;;
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment