php – 通过SSH获取CPU使用率

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 通过SSH获取CPU使用率脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我想通过SSH检索cpu利用率百分比,我尝试了命令“top”,但它不会让我.

我正在使用CentOS 6.

我试过这段代码

@H_304_11@$connection = ssh2_connect("IP",PORT); ssh2_auth_password($connection,"root","PASS"); $stream = ssh2_exec($connection,"top"); $errorStream = ssh2_fetch_stream($stream,SSH2_STREAM_STDERR); // Enable blocking for both streams stream_set_blocking($errorStream,true); stream_set_blocking($stream,true); // whichever of the two below commands is listed First will receive ITs apPRopriate output. The second command receives nothing echo "Output: " . stream_get_contents($stream); echo "Error: " . stream_get_contents($errorStream); // Close the streams fclose($errorStream); fclose($stream);

但它每次都给我一个错误输出错误:未设置TERM环境变量.

我正在使用PHP.

解决方法

谢谢大家,但我做到了.
我做了这个命令:

top -b -n 10 -d.2 | grep 'cpu' |  awk 'NR==3{ print($2)}'

脚本宝典总结

以上是脚本宝典为你收集整理的php – 通过SSH获取CPU使用率全部内容,希望文章能够帮你解决php – 通过SSH获取CPU使用率所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。