Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icinga-checks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Merge requests
!131
netio - add help; add param -i
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
netio - add help; add param -i
6468-docs-and-harmonize
into
master
Overview
0
Commits
2
Pipelines
0
Changes
1
Merged
Hahn Axel (hahn)
requested to merge
6468-docs-and-harmonize
into
master
1 year ago
Overview
0
Commits
2
Pipelines
0
Changes
1
0
0
Merge request reports
Compare
master
version 1
29f5b93f
1 year ago
master (base)
and
version 1
latest version
40a1685c
2 commits,
1 year ago
version 1
29f5b93f
1 commit,
1 year ago
1 file
+
90
−
34
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
check_netio
+
90
−
34
View file @ 29f5b93f
Edit in single-file editor
Open in Web IDE
Show full file
@@ -6,19 +6,66 @@
#
# ----------------------------------------------------------------------
# 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
# ----------------------------------------------------------------------
bOptHelp
=
$(
ph.hasParamoption
"h"
"
$@
"
)
if
[
$bOptHelp
-eq
1
]
;
then
showHelp
exit
0
fi
tmpfile1
=
`
mktemp
`
tmpfile2
=
`
mktemp
`
typeset
-i
iCountInterfaces
typeset
-i
iRead
=
0
typeset
-i
iTrans
=
0
typeset
-i
iSpeedRead
=
0
@@ -26,54 +73,63 @@ typeset -i iSpeedTrans=0
typeset
-i
iTotalRead
=
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]*)"
)
allInterfaces
=
$(
cut
-f
1
-d
":"
<<<
"
$data
"
|
tr
-d
" "
)
sInterface
=
$(
ph.getValueWithParam
"
$allInterfaces
"
"i"
"
$@
"
)
for
myinterface
in
`
cat
$tmpfile1
|
cut
-f
1
-d
":"
|
tr
-d
" "
`
iCountInterfaces
=
$(
wc
-w
<<<
"
$sInterface
"
)
for
myinterface
in
$sInterface
do
echo
>>
$tmpfile2
echo
"---
$myinterface
"
>>
$tmpfile2
line
=
`
grep
"
${
myinterface
}
\
:
"
$tmpfile1
`
# echo "SOURCE: $line" >> $tmpfile2
echo
>>
"
$tmpfile2
"
echo
"---
$
{
myinterface
}
:
"
>>
"
$tmpfile2
"
line
=
$(
grep
"
${
myinterface
}
:"
<<<
"
$data
"
)
if
[
-n
"
$line
"
]
;
then
# total value of byte
iRead
=
`
echo
$line
|
awk
'{ print $2 }'
`
iTrans
=
`
echo
$line
|
awk
'{ print $10 }'
`
# echo "SOURCE: $line" >> $tmpfile2
# speed in byte per sec based on last stored value and its ag
e
i
SpeedRead
=
`
ph.perfdeltaspeed
"netio-
${
myinterface
}
-rx"
$iRead
`
i
Speed
Trans
=
`
ph.perfdeltaspeed
"netio-
${
myinterface
}
-tx"
$iTrans
`
# total value of byt
e
i
Read
=
$(
echo
"
$line
"
|
awk
'{ print $2 }'
)
iTrans
=
$(
echo
"
$line
"
|
awk
'{ print $10 }'
)
# echo " > receive : $iRead .. $iSpeedRead byte/s" >> $tmpfile2
# echo " > transmit: $iTrans .. $iSpeedTrans byte/s" >> $tmpfile2
# 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
)
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
"
"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"
# to store data for each interface
if
[
$iCountInterfaces
-gt
1
]
;
then
ph.perfadd
"rx-
${
myinterface
}
"
"
$iSpeedRead
"
ph.perfadd
"tx-
${
myinterface
}
"
"
$iSpeedTrans
"
fi
iTotalRead
=
$iTotalRead
+
$iSpeedRead
iTotalTrans
=
$iTotalTrans
+
$iSpeedTrans
else
ph.setStatus
"unknown"
echo
"UNKNOWN: the interface
${
myinterface
}
does not exist."
>>
"
$tmpfile2
"
fi
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
echo
""
>>
"
$tmpfile2
"
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
"
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"
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
Loading