1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#!/bin/bash CGROUP_DIR=/sys/fs/cgroup/memory UNLIMITTED=9223372036854771712 read mem_total <$CGROUP_DIR/memory.limit_in_bytes read mem_used <$CGROUP_DIR/memory.usage_in_bytes mem_free=$((mem_total - mem_used)) read mem_swap_total <$CGROUP_DIR/memory.memsw.limit_in_bytes read mem_swap_used <$CGROUP_DIR/memory.memsw.usage_in_bytes swap_total=$((mem_swap_total - mem_total)) swap_used=$((mem_swap_used - mem_used)) swap_free=$((swap_total - swap_used)) if [[ $mem_total = "9223372036854771712" ]];then /usr/bin/free -h && exit fi printf "%20s%20s%20s\n" total used free printf "Mem:%16s%20s%20s\n" $((mem_total/1024/1024))M $((mem_used/1024/1024))M $((mem_free/1024/1024))M printf "Swap:%15s%20s%20s\n" $((swap_total/1024/1024))M $((swap_used/1024/1024))M $((swap_free/1024/1024))M |