Skip to content

Commit

Permalink
add exception handling for networks stats
Browse files Browse the repository at this point in the history
If the container uses `bridge` mode there are no network stats.
  • Loading branch information
markwell-ch authored Dec 10, 2019
1 parent 1e78ca6 commit 18c3233
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions docker_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 18c3233

Please sign in to comment.