April 17, 2010

Openvz pretty printing disk usage

Second verse almost the same as the first.

/usr/sbin/vzlist -o ctid,hostname,diskspace,diskspace.s | \
awk 'BEGIN { totalused=0; totalquota=0; } \
$1 ~ /CTID/ { printf "%5s %20s %6s %6s\n", $1, $2, "used", "quota"; next; } \
$1 ~ /[0-9]+/ { totalused += $3; totalquota += $4; split($2, arr, /\./); \
printf "%5s %20s %6.2f %6.2f\n", $1, arr[1], $3 / 1024 / 1024, $4 / 1024 / 1024; } \
END { printf "total %20s %6.2f %6.2f\n", "", totalused / 1024 / 1024, totalquota / 1024 / 1024; }'