使用PHP获取Linux中当前的带宽使用情况 [英] Get the current bandwidth use in Linux with PHP

查看:243
本文介绍了使用PHP获取Linux中当前的带宽使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台安装了OpenVZ的服务器,并且每台机器都有一个带有公用IPv4的虚拟机. 我需要从PHP获取每个单独的虚拟机(mbps或kbps)的带宽使用情况. 我的想法是在主机上安装iftop并从PHP函数exec()(命令"iftop -n -F AA.BB.CC.DD/32")运行它. 问题在于这是应用程序iftop"top"样式,并且使其在真实终端上运行,并使用新数据进行了更新. 我无法在VM上安装任何东西,应该干净. 每个VM都没有网络接口,我无法更改它. 我想知道我还有什么其他选择或如何实现我的想法. 对不起,我的英语

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

推荐答案

如果guest虚拟机也正在运行Linux,或者它们在主机上具有单独的接口,则可以使用/sys/class/net/$ interface_name/statistics/rx_bytes和tx_bytes,只需比较差异并除以时间即可得出当前吞吐量的估算值.

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.

这篇关于使用PHP获取Linux中当前的带宽使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆