Skip to content

Commit 12f4c42

Browse files
authored
Major update, mainly better version checks. (#30)
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
1 parent 5069b9e commit 12f4c42

File tree

7 files changed

+1313
-1481
lines changed

7 files changed

+1313
-1481
lines changed

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ python:
44
- "3.4"
55
- "3.5"
66
- "3.6"
7+
- "3.7-dev"
78
install:
8-
- pip install codeclimate-test-reporter coverage==4.3.4 pyfakefs
9+
- pip install codeclimate-test-reporter coverage==4.3.4 pyfakefs pytest
910
# command to run tests
1011
script:
11-
- COVERAGE_FILE=.coverage.check_docker coverage run ./test_check_docker.py
12-
- COVERAGE_FILE=.coverage.check_swarm coverage run ./test_check_swarm.py
13-
- coverage combine .coverage.check_*
12+
- coverage run --include='check_*' -m pytest
1413
- codeclimate-test-reporter || echo "Ignoring Code Climate reporter upload failure"

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ With check_docker can use it to check and alert on
1717
- container health checks are passing?
1818
- uptime, i.e. is it able to stay running for a long enough time?
1919
- the presence of a container or containers matching specified names
20-
- image version (experimental!), does the running image match that in the remote registry?
20+
- image version, does the running image match that in the remote registry?
2121

2222
With check_swarm you can alert
2323

@@ -56,11 +56,13 @@ With wget
5656
usage: check_docker [-h]
5757
[--connection [/<path to>/docker.socket|<ip/host address>:<port>]
5858
| --secure-connection [<ip/host address>:<port>]]
59-
[--timeout TIMEOUT]
59+
[--binary_units | --decimal_units] [--timeout TIMEOUT]
6060
[--containers CONTAINERS [CONTAINERS ...]] [--present]
6161
[--cpu WARN:CRIT] [--memory WARN:CRIT:UNITS]
6262
[--status STATUS] [--health] [--uptime WARN:CRIT]
63-
[--version] [--restarts WARN:CRIT]
63+
[--version]
64+
[--insecure-registries INSECURE_REGISTRIES [INSECURE_REGISTRIES ...]]
65+
[--restarts WARN:CRIT]
6466

6567
Check docker containers.
6668

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

96106
## check_swarm Usage

README.txt

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ With check_docker can use it to check and alert on
2020
- container health checks are passing?
2121
- uptime, i.e. is it able to stay running for a long enough time?
2222
- the presence of a container or containers matching specified names
23-
- image version (experimental!), does the running image match that in
24-
the remote registry?
23+
- image version, does the running image match that in the remote registry?
2524

2625
With check_swarm you can alert
2726

@@ -39,45 +38,55 @@ check_docker Usage
3938

4039
::
4140

42-
usage: check_docker [-h]
43-
[--connection [/<path to>/docker.socket|<ip/host address>:<port>]
44-
| --secure-connection [<ip/host address>:<port>]]
45-
[--timeout TIMEOUT]
46-
[--containers CONTAINERS [CONTAINERS ...]] [--present]
47-
[--cpu WARN:CRIT] [--memory WARN:CRIT:UNITS]
48-
[--status STATUS] [--health] [--uptime WARN:CRIT]
49-
[--version] [--restarts WARN:CRIT]
50-
51-
Check docker containers.
52-
53-
optional arguments:
54-
-h, --help show this help message and exit
55-
--connection [/<path to>/docker.socket|<ip/host address>:<port>]
56-
Where to find docker daemon socket. (default:
57-
/var/run/docker.sock)
58-
--secure-connection [<ip/host address>:<port>]
59-
Where to find TLS protected docker daemon socket.
60-
--timeout TIMEOUT Connection timeout in seconds. (default: 10.0)
61-
--containers CONTAINERS [CONTAINERS ...]
62-
One or more RegEx that match the names of the
63-
container(s) to check. If omitted all containers are
64-
checked. (default: ['all'])
65-
--present Modifies --containers so that each RegEx must match at
66-
least one container.
67-
--cpu WARN:CRIT Check cpu usage percentage taking into account any
68-
limits. Valid values are 0 - 100.
69-
--memory WARN:CRIT:UNITS
70-
Check memory usage taking into account any limits.
71-
Valid values for units are %,b,k,m,g.
72-
--status STATUS Desired container status (running, exited, etc).
73-
(default: None)
74-
--health Check container's health check status
75-
--uptime WARN:CRIT Minimum container uptime in seconds. Use when
76-
infrequent crashes are tolerated.
77-
--version Check if the running images are the same version as
78-
those in the registry. Useful for finding stale
79-
images. Only works with public registry.
80-
--restarts WARN:CRIT Container restart thresholds.
41+
usage: check_docker [-h]
42+
[--connection [/<path to>/docker.socket|<ip/host address>:<port>]
43+
| --secure-connection [<ip/host address>:<port>]]
44+
[--binary_units | --decimal_units] [--timeout TIMEOUT]
45+
[--containers CONTAINERS [CONTAINERS ...]] [--present]
46+
[--cpu WARN:CRIT] [--memory WARN:CRIT:UNITS]
47+
[--status STATUS] [--health] [--uptime WARN:CRIT]
48+
[--version]
49+
[--insecure-registries INSECURE_REGISTRIES [INSECURE_REGISTRIES ...]]
50+
[--restarts WARN:CRIT]
51+
52+
Check docker containers.
53+
54+
optional arguments:
55+
-h, --help show this help message and exit
56+
--connection [/<path to>/docker.socket|<ip/host address>:<port>]
57+
Where to find docker daemon socket. (default:
58+
/var/run/docker.sock)
59+
--secure-connection [<ip/host address>:<port>]
60+
Where to find TLS protected docker daemon socket.
61+
--binary_units Use a base of 1024 when doing calculations of KB, MB,
62+
GB, & TB (This is default)
63+
--decimal_units Use a base of 1000 when doing calculations of KB, MB,
64+
GB, & TB
65+
--timeout TIMEOUT Connection timeout in seconds. (default: 10.0)
66+
--containers CONTAINERS [CONTAINERS ...]
67+
One or more RegEx that match the names of the
68+
container(s) to check. If omitted all containers are
69+
checked. (default: ['all'])
70+
--present Modifies --containers so that each RegEx must match at
71+
least one container.
72+
--cpu WARN:CRIT Check cpu usage percentage taking into account any
73+
limits. Valid values are 0 - 100.
74+
--memory WARN:CRIT:UNITS
75+
Check memory usage taking into account any limits.
76+
Valid values for units are %,B,KB,MB,GB.
77+
--status STATUS Desired container status (running, exited, etc).
78+
(default: None)
79+
--health Check container's health check status
80+
--uptime WARN:CRIT Minimum container uptime in seconds. Use when
81+
infrequent crashes are tolerated.
82+
--version Check if the running images are the same version as
83+
those in the registry. Useful for finding stale
84+
images. Does not support login.
85+
--insecure-registries INSECURE_REGISTRIES [INSECURE_REGISTRIES ...]
86+
List of registries to connect to with http(no TLS).
87+
Useful when using "--version" with images from
88+
insecure registries.
89+
--restarts WARN:CRIT Container restart thresholds.
8190

8291
check_swarm Usage
8392
-----------------

0 commit comments

Comments
 (0)