Get current bandwidth usage on Linux using PHP

I have a server with OpenVZ installed and open IPv4 virtual machines for each machine. I need to get the bandwidth usage of each individual virtual machine (mbps or kbps) with PHP. My idea is to install iftop on the host machine and start it from the PHP exec () function, the command "iftop -n -F AA.BB.CC.DD / 32". The problem is that this is an iftop "top" application, and it runs on a real terminal and updates with new data. I can’t install anything on virtual machines, it must be clean. There is also no network interface for each virtual machine, and I cannot change it. I wonder what other options I have and how to realize my idea. sorry for my English

+4
source share
1 answer

If guests also have Linux running or they have separate host interfaces, you can use cat / sys / class / net / $ interface_name / statistics / rx_bytes and tx_bytes, just compare the difference and share the time to get an estimate of the current bandwidth.

+5
source

All Articles