From 18c32331fac92decf4847e8b501b0a8caeb884d9 Mon Sep 17 00:00:00 2001 From: markwell-ch <43644469+markwell-ch@users.noreply.github.com> Date: Tue, 10 Dec 2019 16:02:54 +0100 Subject: [PATCH] add exception handling for networks stats If the container uses `bridge` mode there are no network stats. --- docker_check.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docker_check.py b/docker_check.py index c97f0a1..96373b8 100755 --- a/docker_check.py +++ b/docker_check.py @@ -60,8 +60,15 @@ def get_cpu_pct(stats): def get_net_io(stats): '''Get a container Net In / Out usage since it's launche''' - net_in = stats['networks']['eth0']['rx_bytes'] - net_out = stats['networks']['eth0']['tx_bytes'] + try: + net_in = stats['networks']['eth0']['rx_bytes'] + except KeyError: + net_in = 0 + try: + net_out = stats['networks']['eth0']['tx_bytes'] + except KeyError: + net_out = 0 + return net_in, net_out