When managing an OpenVZ or Virtuozzo hardware node hosting dozens of virtual environments, running standard vzlist doesn’t immediately tell you which containers are running dangerously close to their allocated disk quota.
Here is a clean Bash one-liner that queries vzlist, sorts containers by disk consumption, and formats a clean table displaying the CTID, hostname, soft/hard disk limits, and calculated percentage used:
vzlist --output ctid,hostname,diskspace,diskspace.s,diskspace.h --sort diskspace | awk '{if (NR>1) {printf("%-4s %-30s %-10s %-10s %-10s %d\n", $1, $2, $3, $4, $5, $3/$4*100)} else printf("%-4s %-30s %-10s %-10s %-10s %s\n", $1, $2, $3, $4, $5, "PERC_USED")}'
Example Terminal Output:
CTID HOSTNAME DISKSPACE DISKSPACE.S DISKSPACE.H PERC_USED
101 ns1.london-hosting.com 2418920 20971520 23068672 11
102 ns2.london-hosting.com 2619440 20971520 23068672 12
105 cpanel01.sysafe.co.uk 18491024 41943040 46137344 44
108 web02.dlan.internal 38914028 41943040 46137344 92
How It Works:
vzlist --output ... --sort diskspace: Extracts container IDs and disk quota limits from kernel parameters.awkformatting: Dynamically divides current usage by the soft limit ($3/$4*100) to output a readable integer percentage alongside the header columnPERC_USED.
