Created
February 11, 2020 14:57
-
-
Save nmaggioni/f7ec0fc3685988aeb1da1d42309c8201 to your computer and use it in GitHub Desktop.
List Proxmox LXC containers by memory usage
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 | |
TMPFILE="$(mktemp)" | |
PCTLIST="$(pct list | grep running | awk '{ print $1 }')" | |
PCTCOUNT="$(echo $PCTLIST | wc -w)" | |
i=0; | |
for id in $PCTLIST; do | |
i=$((i+1)) | |
echo -ne "Analyzing $i/$PCTCOUNT...\r" | |
STATUS="$(pct status $id -verbose)" | |
NAME="$(echo $STATUS | grep -Po '\sname: \K\w+')" | |
MAXMEM="$(echo $STATUS | grep -Po '\smaxmem: \K[0-9]+')" | |
MEM="$(echo $STATUS | grep -Po '\smem: \K[0-9]+')" | |
MEMPCT=$(( ($MEM * 100) / $MAXMEM )) | |
echo "$id $NAME $(($MEM/1000000)) $(($MAXMEM/1000000)) ${MEMPCT}%" >> "$TMPFILE" | |
done | |
undl="$(printf '\u001b[4m')" | |
nrml="$(printf '\u001b[0m')" | |
awk '{ print substr($NF, 1, length($NF)-1) " " $0 }' "$TMPFILE" | sort -nr | cut -d' ' -f2- | sed "1i${undl}ID${nrml} ${undl}NAME${nrml} ${undl}USED_MB${nrml} ${undl}TOTAL_MB${nrml} ${undl}USED_PCT${nrml}" | column -t | |
rm "$TMPFILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment