Commit ec743728 authored by Simon Cornet's avatar Simon Cornet
Browse files

feat: improve motd memory usage for lxc

parent f89ecf46
Loading
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
#!/bin/sh

# distribution information
if [ -f /etc/os-release ]; then
  . /etc/os-release
@@ -11,8 +10,17 @@ fi
# disk usage
disk_usage=$(df -h / | awk 'NR==2 {print $3 " / " $2 " (" $5 ")"}')

# memory usage
# memory usage (cgroup aware for LXC)
if [ -f /sys/fs/cgroup/memory.current ]; then
  mem_used_kb=$(awk '{print int($1/1024)}' /sys/fs/cgroup/memory.current)
  mem_total_kb=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
  mem_used_mb=$((mem_used_kb / 1024))
  mem_total_mb=$((mem_total_kb / 1024))
  mem_pct=$((mem_used_kb * 100 / mem_total_kb))
  memory_usage="$mem_used_mb MB / $mem_total_mb MB ($mem_pct%)"
else
  memory_usage=$(free -m | awk 'NR==2 {print $3 " MB / " $2 " MB (" int($3/$2*100) "%)"}')
fi

# display motd
echo "Welcome to $(hostname)!"
@@ -20,4 +28,3 @@ echo ""
echo -e "$linux_distribution"
echo "Disk Usage: $disk_usage"
echo "Memory Usage: $memory_usage"
echo ""