Get the current bandwidth use in Linux with PHP

蓝咒 提交于 2019-12-06 05:24:52

问题


I have a server with OpenVZ installed and virtual machines with a public IPv4 for every machine. I need to get the bandwidth usage of each separate virtual machine (mbps or kbps) from PHP. My idea is to install iftop on the host machine and run it from PHP function exec(), the command "iftop -n -F AA.BB.CC.DD/32". The problem is that is an application iftop "top" style, and is made to run on a real terminal and is updated with new data. I can not install anything on the VMs, should be clean. Nor has a network interface each VM and I can not change it. I wonder what other options I have or how to carry out my idea. Sorry for my english


回答1:


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



来源:https://stackoverflow.com/questions/4066029/get-the-current-bandwidth-use-in-linux-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!