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
Commits
3d5a77be
Commit
3d5a77be
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
add check_docker_io
parent
160ff929
No related branches found
No related tags found
1 merge request
!244
Docker checks: add docker net io
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_docker_io
+153
-0
153 additions, 0 deletions
check_docker_io
with
153 additions
and
0 deletions
check_docker_io
0 → 100755
+
153
−
0
View file @
3d5a77be
#!/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
# ----------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment