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
!237
add check_dockercontainer_top
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
add check_dockercontainer_top
docker-checks
into
master
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Hahn Axel (hahn)
requested to merge
docker-checks
into
master
1 year ago
Overview
0
Commits
1
Pipelines
0
Changes
1
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
9dec5a19
1 commit,
1 year ago
1 file
+
138
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
check_dockercontainer_top
0 → 100755
+
138
−
0
View file @ 9dec5a19
Edit in single-file editor
Open in Web IDE
#!/bin/bash
# ======================================================================
#
# Check DOCKER PROCESSES
#
# requirements:
# - docker
# - sudo permissions on docker command
# - jq
#
# ----------------------------------------------------------------------
# Cli docs:
# https://docs.docker.com/engine/reference/commandline/docker/
# ----------------------------------------------------------------------
# 2024-01-26 v1.0 <axel.hahn@unibe.ch> init
# ======================================================================
.
$(
dirname
$0
)
/inc_pluginfunctions
.
$(
dirname
$0
)
/inc_dockerfunctions.sh
self_APPVERSION
=
1.0
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
# show help
function
_showHelp
(){
local
_self
=
$(
basename
$0
)
cat
<<
EOH
$(
ph.showImlHelpHeader
)
Show counts and processes of docker containers.
It returns
CRITICAL if a created container is not running.
OK if no container was created yet or all conmtainers are running.
UNKNOWM if
- docker or jq were not found
- docker data were not fetched
- docker cannot be connected
This check provides performance data.
USAGE:
$_self
[OPTIONS]
OPTIONS:
-h, --help this help
-d, --debug Debug; Flag: show all docker system infos
-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.
EXAMPLES:
$_self
Show processes of all containers
$_self
-c
Show processes of all containers and a list of container names with its
status. Warning: this feature uses docker ps --all and can be slow.
$_self
-e
Show processes of all containers. If not all containers are running you
get a list of container names with its status.
$_self
-p /usr/bin
Show processes of all containers. The docker binary will be searched in
given path first - then in all other dirs of
\$
PATH
$_self
-d
Show processes of all containers and json with all docker system infos.
EOH
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
bOptDebug
=
0
while
[[
"$#"
-gt
0
]]
;
do case
$1
in
-h
|
--help
)
_showHelp
;
exit
0
;;
-d
|
--debug
)
bOptDebug
=
1
;
shift
;;
-p
|
--path
)
if
!
grep
":{
$2
}:"
<<<
":{
$PATH
}:"
>
/dev/null
;
then
PATH
=
"
$2
:
$PATH
"
;
fi
shift
;
shift
;;
-t
|
--target
)
export
DOCKER_HOST
=
"
$2
"
;
shift
;
shift
;;
*
)
echo
"ERROR: Unknown parameter:
$1
"
;
showHelp
;
exit
1
;
esac
;
done
ph.require
"docker"
ph.require
"jq"
_detectDockerenv
# --- fetch data
data
=
$(
sudo
-n
--preserve-env
docker ps
--format
"{{ json . }}"
2>/dev/null
)
_detectDockererror
"
$data
"
# --- collect data
out
=
$(
echo
"
$data
"
|
while
read
-r
line
;
do
id
=
$(
echo
"
$line
"
| jq
-r
".ID"
)
name
=
$(
echo
"
$line
"
| jq
-r
".Names"
)
pslist
=
$(
sudo
-n
--preserve-env
docker top
"
$id
"
"-o user,pid,pcpu,pmem,command"
2>/dev/null
)
typeset
-i
ipLines
;
ipLines
=
$(
echo
"
$pslist
"
|
wc
-l
)
-1
echo
"----------|
$ipLines
|--
$name
(id:
$id
) ----- "
echo
"
$pslist
"
done
)
typeset
-i
iContainers
;
iContainers
=
$(
echo
"
$data
"
|
wc
-l
)
typeset
-i
iLines
;
iLines
=
$(
echo
"
$out
"
|
wc
-l
)
typeset
-i
iProcesses
;
iProcesses
=
iLines-iContainers
*
2
# --- output
ph.perfadd
"processes"
"
$iProcesses
"
""
""
ph.status
"Docker processes:
$iProcesses
.. containers:
$iContainers
"
echo
"
$out
"
# 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