Skip to content

Commit 11eeda2

Browse files
committed
Refactored arguments
1 parent 1edb599 commit 11eeda2

File tree

3 files changed

+52
-52
lines changed

3 files changed

+52
-52
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
### Usage example
1313

14-
```
14+
```bash
1515
# default usage
1616
./check_container_stats_docker.py -c containername
1717
OK - containername (b343972b5de9) is Up 3 days - CPU: 8.65%, Memory: 10.62 GiB, PIDs: 304 | cpu=8.65%;;;; pids=304;;;; mem=11403138171B;;;;33565169418 net_send=2570000000B;;;; net_recv=2750000000B;;;; disk_read=1580000000B;;;; disk_write=3760000000B;;;;
@@ -25,14 +25,13 @@ OK - containername (b343972b5de9) is Up 3 days - CPU: 8.65%, Memory: 10.62 GiB,
2525

2626
### Usage
2727
```
28-
./check_container_stats_docker.py --help
2928
usage: check_container_stats_docker.py [-h] -c CONTAINER_NAME [-t TIMEOUT]
30-
[-s SOCKET] [--cpuwarn CPUWARN]
31-
[--cpucrit CPUCRIT] [--memwarn MEMWARN]
32-
[--memcrit MEMCRIT] [--pidwarn PIDWARN]
33-
[--pidcrit PIDCRIT] [--wildcard]
29+
[-s SOCKET] [--wildcard]
30+
[--cpuwarn CPUWARN] [--cpucrit CPUCRIT]
31+
[--memwarn MEMWARN] [--memcrit MEMCRIT]
32+
[--pidwarn PIDWARN] [--pidcrit PIDCRIT]
3433
35-
Icinga/Nagios plugin which statistics of a Container
34+
Icinga/Nagios plugin which checks health and statistics of a Container
3635
3736
optional arguments:
3837
-h, --help show this help message and exit
@@ -43,14 +42,16 @@ optional arguments:
4342
-s SOCKET, --socket SOCKET
4443
Path to Docker socket, sets environment variable
4544
DOCKER_HOST
45+
--wildcard --container is a wildcard, not an exact match
46+
47+
Thresholds:
4648
--cpuwarn CPUWARN warning threshold for CPU usage (in %)
4749
--cpucrit CPUCRIT critical threshold for CPU usage (in %)
4850
--memwarn MEMWARN warning threshold for memory usage (in Bytes)
4951
--memcrit MEMCRIT critical threshold for memory usage (in Bytes)
5052
--pidwarn PIDWARN warning threshold for number of processes in container
5153
--pidcrit PIDCRIT critical threshold for number of processes in
5254
container
53-
--wildcard --container is a wildcard, not an exact match
5455
```
5556

5657
![Icinga2 service check](img/check_container_stats_1.png?raw=true "Icinga2 service check")

check_container_stats_docker.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
def get_args():
2525
""" Parse Arguments """
2626
parser = ArgumentParser(
27-
description="Icinga/Nagios plugin which statistics of a \
28-
Container",
29-
epilog=""
30-
)
27+
description="Icinga/Nagios plugin which checks health and statistics of a \
28+
Container")
3129
parser.add_argument("-c", "--container", required=True,
3230
help="Name of the Container which should be checked",
3331
type=str, dest='container_name')
@@ -39,26 +37,28 @@ def get_args():
3937
DOCKER_HOST",
4038
type=str, dest='socket',
4139
default="unix:///var/run/docker.sock")
42-
parser.add_argument("--cpuwarn", required=False,
43-
help="warning threshold for CPU usage (in %%)",
44-
type=float, dest='cpuwarn')
45-
parser.add_argument("--cpucrit", required=False,
46-
help="critical threshold for CPU usage (in %%)",
47-
type=float, dest='cpucrit')
48-
parser.add_argument("--memwarn", required=False,
49-
help="warning threshold for memory usage (in Bytes)",
50-
type=int, dest='memwarn')
51-
parser.add_argument("--memcrit", required=False,
52-
help="critical threshold for memory usage (in Bytes)",
53-
type=int, dest='memcrit')
54-
parser.add_argument("--pidwarn", required=False,
55-
help="warning threshold for number of processes in container",
56-
type=int, dest='pidwarn')
57-
parser.add_argument("--pidcrit", required=False,
58-
help="critical threshold for number of processes in container",
59-
type=int, dest='pidcrit')
6040
parser.add_argument('--wildcard', dest='wildcard', action='store_true',
6141
help="--container is a wildcard, not an exact match")
42+
thresholds = parser.add_argument_group('Thresholds')
43+
thresholds.add_argument("--cpuwarn", required=False,
44+
help="warning threshold for CPU usage (in %%)",
45+
type=float, dest='cpuwarn')
46+
thresholds.add_argument("--cpucrit", required=False,
47+
help="critical threshold for CPU usage (in %%)",
48+
type=float, dest='cpucrit')
49+
thresholds.add_argument("--memwarn", required=False,
50+
help="warning threshold for memory usage (in Bytes)",
51+
type=int, dest='memwarn')
52+
thresholds.add_argument("--memcrit", required=False,
53+
help="critical threshold for memory usage (in Bytes)",
54+
type=int, dest='memcrit')
55+
thresholds.add_argument("--pidwarn", required=False,
56+
help="warning threshold for number of processes in container",
57+
type=int, dest='pidwarn')
58+
thresholds.add_argument("--pidcrit", required=False,
59+
help="critical threshold for number of processes in container",
60+
type=int, dest='pidcrit')
61+
6262
args = parser.parse_args()
6363
return args
6464

check_container_stats_podman.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,33 @@
2525
def get_args():
2626
""" Parse Arguments """
2727
parser = ArgumentParser(
28-
description="Icinga/Nagios plugin which statistics of a \
29-
Container",
30-
epilog=""
31-
)
28+
description="Icinga/Nagios plugin which checks health and statistics of a \
29+
Container")
3230
parser.add_argument("-c", "--container", required=True,
3331
help="Name of the Container which should be checked",
3432
type=str, dest='container_name')
3533
parser.add_argument("-t", "--timeout", required=False,
3634
help="timeout in seconds", type=int, dest='timeout',
3735
default=10)
38-
parser.add_argument("--cpuwarn", required=False,
39-
help="warning threshold for CPU usage (in %%)",
40-
type=float, dest='cpuwarn')
41-
parser.add_argument("--cpucrit", required=False,
42-
help="critical threshold for CPU usage (in %%)",
43-
type=float, dest='cpucrit')
44-
parser.add_argument("--memwarn", required=False,
45-
help="warning threshold for memory usage (in Bytes)",
46-
type=int, dest='memwarn')
47-
parser.add_argument("--memcrit", required=False,
48-
help="critical threshold for memory usage (in Bytes)",
49-
type=int, dest='memcrit')
50-
parser.add_argument("--pidwarn", required=False,
51-
help="warning threshold for number of processes in container",
52-
type=int, dest='pidwarn')
53-
parser.add_argument("--pidcrit", required=False,
54-
help="critical threshold for number of processes in container",
55-
type=int, dest='pidcrit')
36+
thresholds = parser.add_argument_group('Thresholds')
37+
thresholds.add_argument("--cpuwarn", required=False,
38+
help="warning threshold for CPU usage (in %%)",
39+
type=float, dest='cpuwarn')
40+
thresholds.add_argument("--cpucrit", required=False,
41+
help="critical threshold for CPU usage (in %%)",
42+
type=float, dest='cpucrit')
43+
thresholds.add_argument("--memwarn", required=False,
44+
help="warning threshold for memory usage (in Bytes)",
45+
type=int, dest='memwarn')
46+
thresholds.add_argument("--memcrit", required=False,
47+
help="critical threshold for memory usage (in Bytes)",
48+
type=int, dest='memcrit')
49+
thresholds.add_argument("--pidwarn", required=False,
50+
help="warning threshold for number of processes in container",
51+
type=int, dest='pidwarn')
52+
thresholds.add_argument("--pidcrit", required=False,
53+
help="critical threshold for number of processes in container",
54+
type=int, dest='pidcrit')
5655
args = parser.parse_args()
5756
return args
5857

0 commit comments

Comments
 (0)