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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Merge requests
!244
Docker checks: add docker net io
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Docker checks: add docker net io
docker-checks
into
master
Overview
0
Commits
2
Pipelines
0
Changes
2
Merged
Hahn Axel (hahn)
requested to merge
docker-checks
into
master
1 year ago
Overview
0
Commits
2
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
03bcb692
2 commits,
1 year ago
2 files
+
159
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
check_docker_io
0 → 100755
+
153
−
0
Options
#!/bin/bash
# ======================================================================
#
# Check DOCKER IO DATA
#
# requirements:
# - docker
# - sudo permissions on docker command
# - jq
# - bc
#
# ----------------------------------------------------------------------
# 2024-02-22 v0.1 <axel.hahn@unibe.ch> init
# ======================================================================
.
$(
dirname
$0
)
/inc_pluginfunctions
.
$(
dirname
$0
)
/inc_dockerfunctions.sh
self_APPVERSION
=
0.1
typeset
-i
iRead
typeset
-i
iTrans
typeset
-i
iSpeedRead
typeset
-i
iSpeedTrans
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
# show help
function
_showHelp
(){
local
_self
=
$(
basename
$0
)
cat
<<
EOH
$(
ph.showImlHelpHeader
)
Show IO data of all docker containers
USAGE:
$_self
[OPTIONS]
OPTIONS:
General:
-h, --help this help
Connect to docker:
-p, --path Custom directory for docker binary
-t, --target Custom docker target; value for DOCKER_HOST
Needed only if Docker does not run on a unix socket or
multiple users run a rootless docker daemon.
mode:
-m, --mode MODE Mode what kind of information to show.
The output of container list is sorted by the maximum
value first.
netio sum of netio of all containers IN and OUT
EXAMPLES:
$_self
-m netio
Show netio of all docker containers
EOH
}
# get a list of all running container names
function
getContainerNames
(){
sudo
-n
--preserve-env
docker ps
--format
'{"Names": "{{.Names}}" }'
|
cut
-f
4
-d
'"'
}
# get process id if a given single container
# param string name of container
function
getPidOfContainer
(){
sudo
-n
--preserve-env
docker inspect
-f
'{{ .State.Pid }}'
"
$1
"
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
bOptDebug
=
0
sMode
=
"all"
while
[[
"$#"
-gt
0
]]
;
do case
$1
in
-h
|
--help
)
_showHelp
;
exit
0
;;
-d
|
--debug
)
bOptDebug
=
1
;
shift
;;
-p
|
--path
)
PATH
=
"
$2
:
$PATH
"
;
shift
;
shift
;;
-m
|
--mode
)
sMode
=
"
$2
"
;
shift
;
shift
;;
-t
|
--target
)
export
DOCKER_HOST
=
"
$2
"
;
shift
;
shift
;;
*
)
echo
"ERROR: Unknown parameter:
$1
"
;
_showHelp
;
exit
1
;
esac
;
done
sLabel
=
"??"
case
"
$sMode
"
in
"netio"
)
sLabel
=
"Docker Network I/O of all containers: %s MB/s IN .. %s MB/s OUT"
;;
*
)
ph.setStatus critical
echo
"ERROR: mode [
$sMode
] is unknown. Use -h to get help."
ph.exit
esac
ph.require
"docker"
ph.require
"jq"
ph.require
"bc"
# --- get data
out
=
$(
for
CONTAINER_NAME
in
$(
getContainerNames
)
do
CONTAINER_PID
=
$(
getPidOfContainer
$CONTAINER_NAME
)
case
"
$sMode
"
in
"netio"
)
data
=
$(
grep
":"
"/proc/
$CONTAINER_PID
/net/dev"
|
grep
-vE
"(lo|bond.*|ppp.*):"
)
iRead
=
$(
echo
"
$data
"
|
awk
'{ sum+=$2} END { print sum;}'
)
iTrans
=
$(
echo
"
$data
"
|
awk
'{ sum+=$3} END { print sum;}'
)
iSpeedRead
=
$(
ph.perfdeltaspeed
"netio-container-
$CONTAINER_NAME
-rx"
$iRead
)
iSpeedTrans
=
$(
ph.perfdeltaspeed
"netio-container-
$CONTAINER_NAME
-tx"
$iTrans
)
printf
"%-20s %10s %10s %15s %15s
\n
"
"
${
CONTAINER_NAME
}
"
"
$iRead
"
"
$iTrans
"
"
$iSpeedRead
B/s"
"
$iSpeedTrans
B/s"
;;
esac
done
)
# --- calc total values over all containers:
iRead
=
$(
echo
"
$out
"
|
awk
'{ sum+=$2} END { print sum;}'
)
iTrans
=
$(
echo
"
$out
"
|
awk
'{ sum+=$3} END { print sum;}'
)
iSpeedRead
=
$(
ph.perfdeltaspeed
"netio-containers-rx"
$iRead
)
iSpeedTrans
=
$(
ph.perfdeltaspeed
"netio-containers-tx"
$iTrans
)
ph.perfadd
"rx"
"
$iSpeedRead
"
ph.perfadd
"tx"
"
$iSpeedTrans
"
# --- output
sLabel
=
$(
printf
"
$sLabel
"
"
$(
ph.toUnit
$iSpeedRead
M 2
)
"
"
$(
ph.toUnit
$iSpeedTrans
M 2
)
"
)
ph.status
"
$sLabel
"
echo
"
$out
"
ph.exit
# if -d was given then show debug infos too
test
$bOptDebug
-eq
1
&&
(
echo
;
echo
"DEBUG: full docker system infos as json"
;
echo
"
$data
"
| jq
;
_debugInfos
)
ph.exit
# ----------------------------------------------------------------------
Loading