Skip to content

Commit

Permalink
Fix KeyError when online_cpus don't exists
Browse files Browse the repository at this point in the history
  • Loading branch information
rnt committed Jan 6, 2018
1 parent 5c4c30c commit 4894486
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docker_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ def get_cpu_pct(stats):
stats['precpu_stats']['cpu_usage']['total_usage']
system_delta = stats['cpu_stats']['system_cpu_usage'] - \
stats['precpu_stats']['system_cpu_usage']
online_cpus = stats['cpu_stats']['online_cpus']
try:
online_cpus = stats['cpu_stats']['online_cpus']
except KeyError:
online_cpus = len([item
for item in stats['cpu_stats']['percpu_usage']
if item > 0])
if cpu_delta > 0 and system_delta > 0:
return (cpu_delta / system_delta) * online_cpus * 100
return 0.0
Expand Down

0 comments on commit 4894486

Please sign in to comment.