feat: improve motd memory usage for lxc
This commit is contained in:
parent
f89ecf464d
commit
ec743728c2
1 changed files with 11 additions and 4 deletions
|
|
@ -1,5 +1,4 @@
|
|||
#!/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=$(free -m | awk 'NR==2 {print $3 " MB / " $2 " MB (" int($3/$2*100) "%)"}')
|
||||
# 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 ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue