Javascript 显示服务器负载并每隔几秒更新一次
我正在尝试在网页上显示服务器负载。通过执行 shell 命令“/proc/loadavg”并按原样显示输出,在 PHP 中获取服务器负载。
但是,我想使用 Javascript 显示相同的输出(jQuery 很好)并每 10 秒更新一次。
我该怎么做?我正在考虑使用 Ajax 查询,但我认为这使事情过于复杂
I am trying to show server load on a web page. The server load is fetched in PHP by executing the shell command "/proc/loadavg" and displaying the output as it is.
However, I want to display the same output using Javascript (jQuery is fine) and have it updated every 10 seconds.
How do I do so? I was thinking of using Ajax query but I think that is overcomplicating things
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你别无选择,只能设置类似 ajax 机制的东西。它不一定是 XMLHttpRequest,但它必须是从浏览器到服务器上的 URL 的某种显式通信。
想一想:Javascript 是在客户端浏览器中运行的。在不实际与服务器通信的情况下如何获得服务器的平均负载?
You have no choice but to set up something like an ajax mechanism. It doesn't have to be XMLHttpRequest but it has to be some explicit communication from the browser to a URL on your server.
Think about it: the Javascript is running inside a client browser. How is it going to get the load average of the server without actually communicating with the server?