`## 运行glances项目
root@ubuntu:/data/docker_data/glances# docker run -d -e GLANCES_OPT="-w" -v /var/run/docker.sock:/var/run/docker.sock:ro --name="glances" --pid host -it nicolargo/glances:latest-full
1b1e167607920b39da3f926cb9bb3c4ca5106a85bd1faa2d8077a6dec8863908
## 进入容器内部
root@ubuntu:/data/docker_data/glances# docker exec -it glances sh
## 设置密码,默认用户名为glances,可以通过--username修改(后续设置复杂不推荐)
/glances # glances -s --password
## 输入两次密码,并保存
Define the Glances server password (glances username):
Password (confirm):
Do you want to save the password? [Yes/No]: yes
Glances XML-RPC server is running on 0.0.0.0:61209
Announce the Glances server on the LAN (using 172.17.0.2 IP address)
## ctrl+c结束任务
^C^C^C^C^C
Exception ignored in: <module 'threading' from '/usr/lib/python3.10/threading.py'>
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1567, in _shutdown
lock.acquire()
File "/usr/lib/python3.10/site-packages/glances/__init__.py", line 65, in __signal_handler
end()
File "/usr/lib/python3.10/site-packages/glances/__init__.py", line 71, in end
mode.end()
File "/usr/lib/python3.10/site-packages/glances/server.py", line 234, in end
self.autodiscover_client.close()
File "/usr/lib/python3.10/site-packages/glances/autodiscover.py", line 238, in close
self.zeroconf.unregister_service(self.info)
File "/usr/lib/python3.10/site-packages/zeroconf/_core.py", line 699, in unregister_service
run_coro_with_timeout(
File "/usr/lib/python3.10/site-packages/zeroconf/_utils/asyncio.py", line 86, in run_coro_with_timeout
raise EventLoopBlocked from ex
zeroconf._exceptions.EventLoopBlocked:
## 退出容器
/glances # exit
root@ubuntu:/data/docker_data/glances#
## 复制生成的密码文件到宿主机
root@ubuntu:/data/docker_data/glances# docker cp glances:/root/.config/glances/glances.pwd ./secrets/glances_password
## 删除容器
root@ubuntu:/data/docker_data/glances# docker rm -f glances
glances`
4.4. 拉去镜像开始安装
`root@ubuntu:/data/docker_data/glances# docker-compose up -d
[+] Running 1/1
⠿ Container glances Started 0.4s
root@ubuntu:/data/docker_data/glances#`
【Docker项目】之–Glances系统资源监控程序支持API调用
手册 #教程 #工具 #Docker #Docker-compose #Linux #Ubuntu #系统 #安全防护
Glances是一个由python开发的跨平台系统资源监控程序,支持web查看、系统数据API调用等功能。
官网地址:https://nicolargo.github.io/glances
Github地址:https://github.com/nicolargo/glances
文档地址:https://glances.readthedocs.io/en/latest
Docker Hub:https://hub.docker.com/r/nicolargo/glances
1. 安装准备
系统:ubuntu 20.4
工具:docker和docker-compose
2. 搭建
Docer控制台运行效果。
下面通过docker-compose搭建,实现web和API调用。
2.1. 创建数据存放位置
2.2. 编辑docker-compose.yml
2.3. 新建docker网络
已经创建的略过。
2.4. 拉去镜像开始安装
3. 使用及展示
打开浏览器访问:http://ip:61208
4. 设置用户密码访问
删除已创建的glances容器。
4.1. 创建密码存放位置
4.2. 编辑docker-compose.yml
4.3. 获取密码文件
4.4. 拉去镜像开始安装
4.5. 登录效果
5. API调用
详细的调用方式查看文档:API (Restfull/JSON) documentation — Glances 3.3.0.1 documentation
6. 关闭web访问
如果仅需要API调用,通过修改
docker-compose.yml
关闭web访问。0