Skip to content

Commit

Permalink
api/servers: handle no stats available better
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vilhelmprytz committed May 4, 2022
1 parent 462f07a commit df4fd00
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions wilfred/api/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def all(self, cpu_load=False, memory_usage=False):
if cpu_load or memory_usage:
for server in servers:
_running = True
_stats_avail = True

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

if cpu_load and _running:
# on some systems, statisics are not available
if (
"system_cpu_usage" not in d["cpu_stats"]
or "system_cpu_usage" not in d["precpu_stats"]
):
server.update({"cpu_load": "-"})
_stats_avail = False

if cpu_load and _running and _stats_avail:
# calculate the change in CPU usage between current and previous reading
cpu_delta = float(
d["cpu_stats"]["cpu_usage"]["total_usage"]
Expand Down

0 comments on commit df4fd00

Please sign in to comment.