Skip to content

Commit df4fd00

Browse files
committed
api/servers: handle no stats available better
when systemd.unified_cgroup_hierarchy=1 is missing from /etc/default/grub, some statistics required when displaying CPU and mem usage in wilfred top will be missing, causing wilfred to crash
1 parent 462f07a commit df4fd00

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

wilfred/api/servers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def all(self, cpu_load=False, memory_usage=False):
6666
if cpu_load or memory_usage:
6767
for server in servers:
6868
_running = True
69+
_stats_avail = True
6970

7071
try:
7172
container = self._docker_client.containers.get(
@@ -82,6 +83,15 @@ def all(self, cpu_load=False, memory_usage=False):
8283
_running = False
8384

8485
if cpu_load and _running:
86+
# on some systems, statisics are not available
87+
if (
88+
"system_cpu_usage" not in d["cpu_stats"]
89+
or "system_cpu_usage" not in d["precpu_stats"]
90+
):
91+
server.update({"cpu_load": "-"})
92+
_stats_avail = False
93+
94+
if cpu_load and _running and _stats_avail:
8595
# calculate the change in CPU usage between current and previous reading
8696
cpu_delta = float(
8797
d["cpu_stats"]["cpu_usage"]["total_usage"]

0 commit comments

Comments
 (0)