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
Commits
9dec5a19
Commit
9dec5a19
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
add check_dockercontainer_top
parent
a58cd2c5
No related branches found
No related tags found
1 merge request
!237
add check_dockercontainer_top
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_dockercontainer_top
+138
-0
138 additions, 0 deletions
check_dockercontainer_top
with
138 additions
and
0 deletions
check_dockercontainer_top
0 → 100755
+
138
−
0
View file @
9dec5a19
#!/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
# ----------------------------------------------------------------------
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