Skip to content
Snippets Groups Projects
Commit 84dc3f67 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

add docker info with count of containers

parent 4de9cff4
Branches
No related tags found
1 merge request!229add docker info with count of containers
#!/bin/bash
# ======================================================================
#
# Check DOCKER INFOS
#
# requirements:
# - docker
#
# ----------------------------------------------------------------------
# Cli docs:
# https://docs.docker.com/engine/reference/commandline/docker/
# ----------------------------------------------------------------------
# 2024-01-18 v1.0 <axel.hahn@unibe.ch> init
# ======================================================================
. $(dirname $0)/inc_pluginfunctions
self_APPVERSION=1.0
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
# show help
function _usage(){
local _self=$( basename $0 )
cat <<EOH
$( ph.showImlHelpHeader )
Show docker version and count of containers total and by its status.
USAGE:
$_self [OPTIONS]
OPTIONS:
-h this help
EXAMPLES:
$_self
EOH
}
# filter json data with jq
# param string json data
# param string jq filter
function _filterJson(){
echo "$1" | jq "$2"
}
# filter json data with jq (by expecting a single result) and remove quotes
# param string json data
# param string jq filter
function _getString(){
_filterJson "$1" "$2" | tr -d '"'
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
ph.hasParamoption "h" "$@"; bOptHelp=$?
if [ $bOptHelp -eq 0 ]; then
_usage
exit 0
fi
ph.require "docker"
ph.require "jq"
# --- get data
data=$( docker system info --format "{{ json . }}" )
typeset -i iCTotal;
iCTotal=$( _getString "$data" ".Containers" )
iCRunning=$(_getString "$data" ".ContainersRunning" )
iCPaused=$( _getString "$data" ".ContainersPaused" )
iCStopped=$(_getString "$data" ".ContainersStopped" )
iImages=$( _getString "$data" ".Images" )
sVersion=$( _getString "$data" ".ServerVersion")
sLicense=$( _getString "$data" ".ProductLicense" )
# --- generate result
if [ "$iCRunning" -eq "0" ]; then
ph.setStatus critical
out+="No container is running"
else
if [ "$iCRunning" -ne "$iCTotal" ]; then
ph.setStatus warning
out+="Not all containers are running"
else
out+="All containers are running"
fi
fi
ph.perfadd "containers-running" "$iCRunning" "" "" 0 "$iCTotal"
ph.perfadd "containers-paused" "$iCPaused" "" "" 0 "$iCTotal"
ph.perfadd "containers-stopped" "$iCStopped" "" "" 0 "$iCTotal"
ph.perfadd "images" "$iImages"
# --- output
ph.status "Docker $sVersion ($sLicense) .. containers: $iCTotal running: $iCRunning paused: $iCPaused stopped: $iCStopped .. images: $iImages"
echo "$out"
ph.exit
# ----------------------------------------------------------------------
...@@ -20,6 +20,7 @@ There is one include script used by all checks: ...@@ -20,6 +20,7 @@ There is one include script used by all checks:
* [check_cronstatus](check_cronstatus.md) * [check_cronstatus](check_cronstatus.md)
* [check_disk-io](check_disk-io.md) * [check_disk-io](check_disk-io.md)
* [check_dns_responsetime](check_dns_responsetime.md) * [check_dns_responsetime](check_dns_responsetime.md)
* [check_docker_info](check_docker_info.md)
* [check_eol](check_eol.md) * [check_eol](check_eol.md)
* [check_fs_errors](check_fs_errors.md) * [check_fs_errors](check_fs_errors.md)
* [check_fs_writable](check_fs_writable.md) * [check_fs_writable](check_fs_writable.md)
......
# CHECK_DOCKER_INFO
## Introduction
**check_docker_info_** shows the docker version and count of containers.
You get the count of containers by state running, paused or stopped.
This check sends performance data.
## Requirements
* `docker` Docker must be installed
## Syntax
```txt
______________________________________________________________________
CHECK_DISK-IO
v1.1
Check dis io and latency
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
______________________________________________________________________
Disk infos based on /sys/block/[NAME]/stat
See https://www.kernel.org/doc/Documentation/block/stat.txt
and https://www.kernel.org/doc/Documentation/iostats.txt
The system data are counters that are difficult to read.
The output of this check for each value a delta value per second since
last check.
SYNTAX:
check_disk-io -m MODE
OPTIONS:
-m MODE set mode for type of output (required)
-h or --help show this help.
PARAMETERS:
MODE
io read I/Os, write I/Os, discard I/0s
ticks read ticks, write ticks, discard ticks
wait total wait time for all requests
EXAMPLE:
check_disk-io -m io
```
### Parameters
`-m <MODE>` where MODE is a string to define kind of output.
## Examples
`$ check_disk-io -m io` returns
```txt
OK: Disk data ... read I/Os, write I/Os, discard I/0s, number of I/Os currently in flight
--- sda
disk-sda-ReadIO: 0
disk-sda-WriteIO: 0
disk-sda-DiscardIO: 0
disk-sda-FlightIO: 0
--- nvme0n1
disk-nvme0n1-ReadIO: 3
disk-nvme0n1-WriteIO: 16
disk-nvme0n1-DiscardIO: 4
disk-nvme0n1-FlightIO: 0
--- TOTAL
ReadIO: 3
WriteIO: 16
DiscardIO: 4
FlightIO: 0
|readio=3;; writeio=16;; discardio=4;; flightio=0;;
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment