Javascript 显示服务器负载并每隔几秒更新一次

发布于 2024-09-13 07:28:28 字数 177 浏览 0 评论 0原文

我正在尝试在网页上显示服务器负载。通过执行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪失控 2024-09-20 07:28:28

你别无选择,只能设置类似 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文