Skip to content

Instantly share code, notes, and snippets.

@alecs
Created January 16, 2023 15:48
Show Gist options
  • Save alecs/cbdb2634b5f77a4fd4697f8191ca7c03 to your computer and use it in GitHub Desktop.
Save alecs/cbdb2634b5f77a4fd4697f8191ca7c03 to your computer and use it in GitHub Desktop.
extract resources per OpenVZ running container
#!/bin/bash
if [[ -f "/usr/sbin/vzlist" ]]; then
vzlist -a | awk '/^\s+[0-9]/ { print $1" "$5 }' | while read ct_id ct_host; do
echo -ne "${ct_host}\t";
vzctl runscript ${ct_id} $0
done
else
CPU=$(awk '/processor/ { cpu+=1 }; END { print cpu }' /proc/cpuinfo);
MEM=$(awk '/^MemTotal:/ { print $2/(1024*1024) }' /proc/meminfo);
DISK=$(df -k | awk '!/^tmp/ && !/^Filesystem/ {mp[$1"-"$2"-"$3]=$3 }; END {for (key in mp){ size+=mp[key]}; print size/(1024*1024)}');
echo -ne "lxc\t${CPU}\t${MEM}\t${DISK}\r\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment