Skip to content

Commit

Permalink
Major update, mainly better version checks. (#30)
Browse files Browse the repository at this point in the history
Note: API change to use the proper units as documented by Nagios. You may notice large jumps in your graphs if units were previously being ignored.
Note: Memory usage no-longer includes cache to match the way ‘docker stats’ does it. You likely will see a drop in memory usage from this.
Made version check much better, it can now handle non-official registries.
Added ability to specify size of a KB (1000 or 1024 bytes)
Moved testing to use Pytest
Added traceback to error handling for better bug reports.
Handle unsupported memory units better, i.e. not with assert.
Adjusted default registry to match Docker documentation.
Round and truncate displayed values as appropriate
  • Loading branch information
timdaman authored Mar 19, 2018
1 parent 5069b9e commit 12f4c42
Show file tree
Hide file tree
Showing 7 changed files with 1,313 additions and 1,481 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ python:
- "3.4"
- "3.5"
- "3.6"
- "3.7-dev"
install:
- pip install codeclimate-test-reporter coverage==4.3.4 pyfakefs
- pip install codeclimate-test-reporter coverage==4.3.4 pyfakefs pytest
# command to run tests
script:
- COVERAGE_FILE=.coverage.check_docker coverage run ./test_check_docker.py
- COVERAGE_FILE=.coverage.check_swarm coverage run ./test_check_swarm.py
- coverage combine .coverage.check_*
- coverage run --include='check_*' -m pytest
- codeclimate-test-reporter || echo "Ignoring Code Climate reporter upload failure"
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ With check_docker can use it to check and alert on
- container health checks are passing?
- uptime, i.e. is it able to stay running for a long enough time?
- the presence of a container or containers matching specified names
- image version (experimental!), does the running image match that in the remote registry?
- image version, does the running image match that in the remote registry?

With check_swarm you can alert

Expand Down Expand Up @@ -56,11 +56,13 @@ With wget
usage: check_docker [-h]
[--connection [/<path to>/docker.socket|<ip/host address>:<port>]
| --secure-connection [<ip/host address>:<port>]]
[--timeout TIMEOUT]
[--binary_units | --decimal_units] [--timeout TIMEOUT]
[--containers CONTAINERS [CONTAINERS ...]] [--present]
[--cpu WARN:CRIT] [--memory WARN:CRIT:UNITS]
[--status STATUS] [--health] [--uptime WARN:CRIT]
[--version] [--restarts WARN:CRIT]
[--version]
[--insecure-registries INSECURE_REGISTRIES [INSECURE_REGISTRIES ...]]
[--restarts WARN:CRIT]

Check docker containers.

Expand All @@ -71,6 +73,10 @@ With wget
/var/run/docker.sock)
--secure-connection [<ip/host address>:<port>]
Where to find TLS protected docker daemon socket.
--binary_units Use a base of 1024 when doing calculations of KB, MB,
GB, & TB (This is default)
--decimal_units Use a base of 1000 when doing calculations of KB, MB,
GB, & TB
--timeout TIMEOUT Connection timeout in seconds. (default: 10.0)
--containers CONTAINERS [CONTAINERS ...]
One or more RegEx that match the names of the
Expand All @@ -82,15 +88,19 @@ With wget
limits. Valid values are 0 - 100.
--memory WARN:CRIT:UNITS
Check memory usage taking into account any limits.
Valid values for units are %,b,k,m,g.
Valid values for units are %,B,KB,MB,GB.
--status STATUS Desired container status (running, exited, etc).
(default: None)
--health Check container's health check status
--uptime WARN:CRIT Minimum container uptime in seconds. Use when
infrequent crashes are tolerated.
--version Check if the running images are the same version as
those in the registry. Useful for finding stale
images. Only works with public registry.
images. Does not support login.
--insecure-registries INSECURE_REGISTRIES [INSECURE_REGISTRIES ...]
List of registries to connect to with http(no TLS).
Useful when using "--version" with images from
insecure registries.
--restarts WARN:CRIT Container restart thresholds.

## check_swarm Usage
Expand Down
91 changes: 50 additions & 41 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ With check_docker can use it to check and alert on
- container health checks are passing?
- uptime, i.e. is it able to stay running for a long enough time?
- the presence of a container or containers matching specified names
- image version (experimental!), does the running image match that in
the remote registry?
- image version, does the running image match that in the remote registry?

With check_swarm you can alert

Expand All @@ -39,45 +38,55 @@ check_docker Usage

::

usage: check_docker [-h]
[--connection [/<path to>/docker.socket|<ip/host address>:<port>]
| --secure-connection [<ip/host address>:<port>]]
[--timeout TIMEOUT]
[--containers CONTAINERS [CONTAINERS ...]] [--present]
[--cpu WARN:CRIT] [--memory WARN:CRIT:UNITS]
[--status STATUS] [--health] [--uptime WARN:CRIT]
[--version] [--restarts WARN:CRIT]

Check docker containers.

optional arguments:
-h, --help show this help message and exit
--connection [/<path to>/docker.socket|<ip/host address>:<port>]
Where to find docker daemon socket. (default:
/var/run/docker.sock)
--secure-connection [<ip/host address>:<port>]
Where to find TLS protected docker daemon socket.
--timeout TIMEOUT Connection timeout in seconds. (default: 10.0)
--containers CONTAINERS [CONTAINERS ...]
One or more RegEx that match the names of the
container(s) to check. If omitted all containers are
checked. (default: ['all'])
--present Modifies --containers so that each RegEx must match at
least one container.
--cpu WARN:CRIT Check cpu usage percentage taking into account any
limits. Valid values are 0 - 100.
--memory WARN:CRIT:UNITS
Check memory usage taking into account any limits.
Valid values for units are %,b,k,m,g.
--status STATUS Desired container status (running, exited, etc).
(default: None)
--health Check container's health check status
--uptime WARN:CRIT Minimum container uptime in seconds. Use when
infrequent crashes are tolerated.
--version Check if the running images are the same version as
those in the registry. Useful for finding stale
images. Only works with public registry.
--restarts WARN:CRIT Container restart thresholds.
usage: check_docker [-h]
[--connection [/<path to>/docker.socket|<ip/host address>:<port>]
| --secure-connection [<ip/host address>:<port>]]
[--binary_units | --decimal_units] [--timeout TIMEOUT]
[--containers CONTAINERS [CONTAINERS ...]] [--present]
[--cpu WARN:CRIT] [--memory WARN:CRIT:UNITS]
[--status STATUS] [--health] [--uptime WARN:CRIT]
[--version]
[--insecure-registries INSECURE_REGISTRIES [INSECURE_REGISTRIES ...]]
[--restarts WARN:CRIT]

Check docker containers.

optional arguments:
-h, --help show this help message and exit
--connection [/<path to>/docker.socket|<ip/host address>:<port>]
Where to find docker daemon socket. (default:
/var/run/docker.sock)
--secure-connection [<ip/host address>:<port>]
Where to find TLS protected docker daemon socket.
--binary_units Use a base of 1024 when doing calculations of KB, MB,
GB, & TB (This is default)
--decimal_units Use a base of 1000 when doing calculations of KB, MB,
GB, & TB
--timeout TIMEOUT Connection timeout in seconds. (default: 10.0)
--containers CONTAINERS [CONTAINERS ...]
One or more RegEx that match the names of the
container(s) to check. If omitted all containers are
checked. (default: ['all'])
--present Modifies --containers so that each RegEx must match at
least one container.
--cpu WARN:CRIT Check cpu usage percentage taking into account any
limits. Valid values are 0 - 100.
--memory WARN:CRIT:UNITS
Check memory usage taking into account any limits.
Valid values for units are %,B,KB,MB,GB.
--status STATUS Desired container status (running, exited, etc).
(default: None)
--health Check container's health check status
--uptime WARN:CRIT Minimum container uptime in seconds. Use when
infrequent crashes are tolerated.
--version Check if the running images are the same version as
those in the registry. Useful for finding stale
images. Does not support login.
--insecure-registries INSECURE_REGISTRIES [INSECURE_REGISTRIES ...]
List of registries to connect to with http(no TLS).
Useful when using "--version" with images from
insecure registries.
--restarts WARN:CRIT Container restart thresholds.

check_swarm Usage
-----------------
Expand Down
Loading

0 comments on commit 12f4c42

Please sign in to comment.