Last active
October 11, 2022 12:41
-
-
Save tataranovich/2ea97830275ffc1e5d5c7cd2ea25750f to your computer and use it in GitHub Desktop.
Display LXC containers memory and swap information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
RAM_TOTAL=0 | |
RAM_TOTAL_MAX=0 | |
SWAP_TOTAL=0 | |
SWAP_TOTAL_MAX=0 | |
printf "%20s\t%11s\t%11s\n" "NAME" "RAM" "SWAP" | |
echo "-------------------------------------------------------" | |
for i in $(find /sys/fs/cgroup -mindepth 1 -maxdepth 1 -type d -name 'lxc.payload.*') | |
do | |
NAME=$(echo $i | sed -e 's@/sys/fs/cgroup/lxc.payload.@@') | |
RAM=$(( $(cat $i/memory.current) / 1024 / 1024 )) | |
RAM_MAX=$(cat $i/memory.max) | |
if [ "$RAM_MAX" != "max" ]; then | |
RAM_MAX=$(( $RAM_MAX / 1024 / 1024 )) | |
fi | |
SWAP=$(( $(cat $i/memory.swap.current ) / 1024 / 1024 )) | |
SWAP_MAX=$(cat $i/memory.swap.max) | |
if [ "$SWAP_MAX" != "max" ]; then | |
SWAP_MAX=$(( $SWAP_MAX / 1024 / 1024 )) | |
fi | |
printf "%20s\t%5s/%5s\t%5s/%5s\n" $NAME $RAM $RAM_MAX $SWAP $SWAP_MAX | |
RAM_TOTAL=$(( $RAM_TOTAL + $RAM )) | |
RAM_TOTAL_MAX=$(( $RAM_TOTAL_MAX + $RAM_MAX )) | |
SWAP_TOTAL=$(( $SWAP_TOTAL + $SWAP )) | |
SWAP_TOTAL_MAX=$(( $SWAP_TOTAL_MAX + $SWAP_MAX )) | |
done | |
echo "-------------------------------------------------------" | |
printf "%20s\t%5s/%5s\t%5s/%5s\n" "TOTAL" $RAM_TOTAL $RAM_TOTAL_MAX $SWAP_TOTAL $SWAP_TOTAL_MAX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output