Skip to content

Commit

Permalink
api/servers: return MEM usage and MEM %
Browse files Browse the repository at this point in the history
* show memory used in MB and memory used in % to limit when running "wilfred top"
  • Loading branch information
vilhelmprytz committed Apr 24, 2022
1 parent 0b92bc2 commit 1ff0a30
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions wilfred/api/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def all(self, cpu_load=False, memory_usage=False):
Args:
cpu_load (bool): Include the CPU load of the container. Defaults to `None` if server is not running.
memory_usage (bool): Include RAM usage of the container. Defaults to `None` if server is not running.
memory_usage (bool): Include memory usage of the container. Defaults to `None` if server is not running.
"""

servers = [
Expand Down Expand Up @@ -105,9 +105,15 @@ def all(self, cpu_load=False, memory_usage=False):
server.update({"cpu_load": cpu_percent if cpu_percent else "-"})

if memory_usage and _running:
mem_used = d["memory_stats"]["usage"] / 1024 / 1024
mem_percent = (
d["memory_stats"]["usage"]
/ d["memory_stats"]["limit"]
* 100
)
server.update(
{
"memory_usage": f"{round(d['memory_stats']['usage'] / 10**6)} MB"
"memory_usage": f"{round(mem_used, 1)} MB / {round(mem_percent, 2)}%"
}
)

Expand Down
2 changes: 1 addition & 1 deletion wilfred/wilfred.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ def top():
"status": click.style("Status", bold=True),
"custom_startup": click.style("Custom startup", bold=True),
"cpu_load": click.style("CPU", bold=True),
"memory_usage": click.style("RAM usage", bold=True),
"memory_usage": click.style("MEM usage / MEM %", bold=True),
}

# display table
Expand Down

0 comments on commit 1ff0a30

Please sign in to comment.