Introduction:

In a Virtuozzo/OpenVZ virtualization environment, server administrators may need to check the load and resource usage of all VPS containers from the main node. Instead of logging in to each VPS manually, we can use a loop command from the hardware node to execute the same command inside all VPS containers. This helps quickly review VPS load, uptime, logged-in users, and other system details.

Prerequisites:

  • Root access to the Virtuozzo/OpenVZ main node
  • vzctl command should be available on the server
  • VPS containers should be running
  • Basic knowledge of Linux commands
  • Permission to execute commands inside VPS containers

Steps:

Step 1: Log in to the main node as root.

ssh root@server-ip

Step 2: List all available VPS containers.

vzlist

Step 3: Run the following command to check the load of all VPS containers:

for i in `vzlist | egrep -v '(VEID|CTID)' | awk '{print $1}'`; do echo "For VEID $i (`vzctl exec $i hostname`) --->"; vzctl exec $i w; echo; done

Step 4: Review the output.

Example output:

For VEID 107 (vpn.xxx.net) --->
04:01:08 up 210 days, 6:01, 0 users, load average: 0.08, 0.02, 0.01
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT

For VEID 109 (xxx.xxx.net) --->
04:01:08 up 210 days, 6:01, 0 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT

Step 5: To run any other command inside all VPS containers, replace w with the required command.

Example to check disk usage:

for i in `vzlist | egrep -v '(VEID|CTID)' | awk '{print $1}'`; do echo "For VEID $i (`vzctl exec $i hostname`) --->"; vzctl exec $i df -h; echo; done

Example to check memory usage:

for i in `vzlist | egrep -v '(VEID|CTID)' | awk '{print $1}'`; do echo "For VEID $i (`vzctl exec $i hostname`) --->"; vzctl exec $i free -m; echo; done

Example to check running processes:

for i in `vzlist | egrep -v '(VEID|CTID)' | awk '{print $1}'`; do echo "For VEID $i (`vzctl exec $i hostname`) --->"; vzctl exec $i ps aux --sort=-%cpu | head; echo; done

Conclusion:

Using this command, administrators can quickly check the load and execute common Linux commands across all VPS containers from the main Virtuozzo/OpenVZ node. This saves time, avoids logging in to each VPS separately, and helps in monitoring server load, disk usage, memory usage, and process activity. It is especially useful during troubleshooting, performance checks, and routine server maintenance.

Leave a Reply