安装
先查看下 Python 版本,如果太低先升级 Python:
root@icexmoon:~# python3 --version
Python 3.8.10
安装 Glances 本体:
root@icexmoon:~# pip install glances[all]
安装好后可以通过以下命令查看帮助文档:
root@icexmoon:~# glances -h
使用
命令行
在命令行模式下可以很容易地通过 Glances 查看资源占用情况:
root@icexmoon:~# glances
浏览器
Glances 还支持 CS 模式查看。
用以下命令启动服务端:
root@icexmoon:~# glances -w
可能会报错,比如
ModuleNotFoundError: No module named 'typing_extensions'
。这说明缺少相应的 Python 模块,安装相应的模块即可,比如pip install typing-extensions
。通过 可以查询相应的模块和安装命令。
如果出现错误Uvicorn import error. Glances cannot start in web server mode.
,需要安装以下模块:
root@icexmoon:~# pip3 install fastapi uvicorn orjson jinja2
如果还报错,可能是端口被防火墙阻止,需要放行端口:
root@icexmoon:~# sudo ufw allow 61208/tcp
配置好后可以检测是否网络可以正常连接:
icexmoon@Awalon:~$ telnet 39.105.60.111 61208 Trying 39.105.60.111... telnet: Unable to connect to remote host: Connection timed out
如果不能连接,可能是防火墙的问题,但也可能是云服务的安全策略的问题。比如我使用的是阿里云,通过安全策略限制外接可以访问的端口:
添加相应的安全策略,开放端口。
现在可以直接通过浏览器查看远程服务器的状况了:
当然这样裸奔不太安全,最好设置一个密码:
root@icexmoon:~# glances -w --password
Define the Glances webserver password (glances username):
现在再通过浏览器访问就需要输入用户名(glances)和密码了。
文章评论