linux docker查看容器状态,Docker容器状态命令行工具——Ctop
Ctop是和Linux top展示效果類似的一個容器狀態(tài)監(jiān)視工具,Ctop可以動態(tài)的顯示容器的cpu、內存、網(wǎng)絡的使用情況。一共有兩個叫Ctop的命令行工具,分別由GO和Python實現(xiàn)。Python實現(xiàn)的版本功能更強大一些。
GO實現(xiàn)版本
安裝
Linux
$ wget https://github.com/bcicen/ctop/releases/download/v0.5/ctop-0.5-linux-amd64 -O ctop
$ sudo mv ctop /usr/local/bin/
$ sudo chmod +x /usr/local/bin/ctop
OS X
方法一
$ brew install ctop
方法二
$ curl -Lo ctop https://github.com/bcicen/ctop/releases/download/v0.5/ctop-0.5-darwin-amd64
$ sudo mv ctop /usr/local/bin/
$ sudo chmod +x /usr/local/bin/ctop
通過Docker安裝
$ docker run -ti --name ctop --rm -v /var/run/docker.sock:/var/run/docker.sock quay.io/vektorlab/ctop:latest
使用
運行前需要使用DOCKER_HOST環(huán)境變量配置下需要管理的Docker進程的地址
$ export DOCKER_HOST=tcp://127.0.0.1:2375
$ ctop
運行效果
選項說明
Option
Description
-a
show active containers only
-f
set an initial filter string
-h
display help dialog
-i
invert default colors
-r
reverse container sort order
-s
select initial container sort field
-v
output version information and exit
常用鍵盤快捷鍵
Key
Action
a
Toggle display of all (running and non-running) containers
f
Filter displayed containers (esc to clear when open)
H
Toggle ctop header
h
Open help dialog
s
Select container sort field
r
Reverse container sort order
q
Quit ctop
Python實現(xiàn)版本
Python實現(xiàn)的Ctop有如下一些功能:
收集cpu,pids,內存和塊輸入輸出的度量值
收集元數(shù)據(jù),比如任務數(shù),屬主、容器技術等相關信息
通過任意欄對信息排序
按照容器類型進行篩選(docker, lxc, systemd, …)
以樹狀視圖顯示信息
折疊/展開cgroup樹
選擇并跟蹤cgroup/容器
選擇顯示數(shù)據(jù)刷新的時間窗口
暫停刷新數(shù)據(jù)
檢測基于systemd、Docker和LXC的容器
Python >= 2.6 or Python >= 3.0沒有外部依賴
基于Docker和LXC的容器的高級特性
打開/連接shell以進行深度診斷
停止/殺死容器類型
安裝
Ctop Python版本需要Python 2.6或其更高版本外(帶有內建的光標支持),別無其它外部依賴。推薦使用Python的pip進行安裝。
安裝pip
$ apt-get install python-pip
安裝ctop
$ pip install ctop
使用
運行
$ ctop
運行效果
當你進入ctop屏幕,可使用上(↑)和下(↓)箭頭鍵在容器間導航。按q或Ctrl+C退出。
選項說明
Monitor local cgroups as used by Docker, LXC, SystemD, ...
Usage:
ctop [--tree] [--refresh=] [--columns=] [--sort-col=] [--follow=] [--fold=, ...] [--type=, ...]
ctop (-h | --help)
Options:
--tree ? ? ? ? ? ? ? ? Show tree view by default.
--fold= ? ? ? ? ?Start with cgroup path folded
--follow= ? ? ? ?Follow/highlight cgroup at path.
--type=TYPE ? ? ? ? ? ?Only show containers of this type
--refresh= ? ?Refresh display every [default: 1].
--columns= ? ?List of optional columns to display. Always includes 'name'. [default: owner,processes,memory,cpu-sys,cpu-user,blkio,cpu-time].
--sort-col= ?Select column to sort by initially. Can be changed dynamically. [default: cpu-user]
-h --help ? ? ? ? ? ? ?Show this screen.
常用鍵盤快捷鍵
press p to toggle/pause the refresh and select text.
press f to let selected line follow / stay on the same container. Default: Don’t follow.
press q or Ctrl+C to quit.
press F5 to toggle tree/list view. Default: list view.
press ↑ and ↓ to navigate between containers.
press + or - to toggle child cgroup folding
click on title line to select sort column / reverse sort order.
click on any container line to select it.
Additionally, for supported container types (Currently Docker, LXC and OpenVZ):
press a to attach to console output.
press e to open a shell in the container context. Aka ‘enter’ container.
press s to stop the container (SIGTERM).
press k to kill the container (SIGKILL).
press c to checkpointing the container(OpenVZ only now – run ‘vzctl chkpnt CTID’)
總結
以上是生活随笔為你收集整理的linux docker查看容器状态,Docker容器状态命令行工具——Ctop的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 并发执行命令_python
- 下一篇: linux 谷歌浏览器设置代理_linu