$ docker stats $CONTAINER_ID
CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O BLOCK I/O
ecb37227ac84 0.12% 71.53 MiB/490 MiB 14.60% 900.2 MB/275.5 MB 266.8 MB/872.7 MB
$ echo -ne "GET /containers/$CONTAINER_ID/stats HTTP/1.1\r\n\r\n" | sudo nc -U /var/run/docker.sock
-
user CPU:CPU使用者行程的時間百分比
-
system CPU:CPU執行系統呼叫的時間百分比
-
CPU util:總的CPU使用率
-
throttling (count):容器的CPU被限制的次數
-
throttling (time):容器的CPU使用率被限制的總時間
$ cat /sys/fs/cgroup/cpuacct/docker/$CONTAINER_ID/cpuacct.stat
> user 2441 # docker開啟後執行使用者行程的時間
> system 985 # docker開啟後執行系統呼叫的時間
$ cat /sys/fs/cgroup/cpuacct/docker/$CONTAINER_ID/cpuacct.usage_percpu
> 44154016900 # docker開啟後單使用CPU的納秒(44.15s)
$ cat /sys/fs/cgroup/cpuacct/docker/$CONTAINER_ID/cpuacct.usage
> 44154016900 # 所有CPU使用的總納秒(44.15s)
$ cat /sys/fs/cgroup/cpu/docker/$CONTAINER_ID/cpu.stat
> nr_periods 565 # 已經過去的執行過的period數
> nr_throttled 559 # CPU被限制的次數
> throttled_time 11219582971 # CPU被限制的總時間,納秒為單位 (11.22 seconds)
-
Memory:容器的記憶體使用
-
RSS:行程除了快取之外的記憶體消耗(包括棧和堆記憶體,等等)
-
Cache memory:記憶體中的磁碟資料快取
-
Swap:swap使用總量
$ cat /sys/fs/cgroup/memory/docker/$CONTAINER_ID/memory.stat
cache
rss
mapped_file
writeback
swap
pgpgin
pgpgout
pgfault
pgmajfault
inactive_anon
active_anon
inactive_file
active_file
unevictable
hierarchical_memory_limit
hierarchical_memsw_limit
total_cache
total_rss
total_rss_huge
total_mapped_file
total_writeback
total_swap
total_pgpgin
total_pgpgout
total_pgfault
total_pgmajfault
total_inactive_anon
total_active_anon
total_inactive_file
total_active_file
total_unevictable
# 總的記憶體使用: cached + rss
$ cat /sys/fs/cgroup/memory/docker/$CONTAINER_ID/memory.usage_in_bytes
# 總的記憶體使用 + swap的使用
$ cat /sys/fs/cgroup/memory/docker/$CONTAINER_ID/memory.memsw.usage_in_bytes
# 記憶體使用達到限制的次數
$ cat /sys/fs/cgroup/memory/docker/$CONTAINER_ID/memory.failcnt
# 容器被限制使用的記憶體值
$ cat /sys/fs/cgroup/memory/docker/$CONTAINER_ID/memory.limit_in_bytes
-
I/O serviced:I/O操作的次數
-
I/O service bytes:讀寫的byte數
253:0 Read 13750272
253:0 Write 180224
253:0 Sync 180224
253:0 Async 13750272
253:0 Total 13930496
-
Bytes:網路流量(包括接收和傳送)
-
Packets:網路包的個數(包括接收和傳送)
-
Error(receive):接收錯誤的資料包個數
-
Error(transmit):傳輸錯誤的資料包個數
-
Dropped:丟棄的包個數(包括接收和傳送)
$ CONTAINER_PID=`docker inspect -f '{{ .State.Pid }}' $CONTAINER_ID`
$ cat /proc/$CONTAINER_PID/net/dev
| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
eth0: 1296 16 0 0 0 0 0 0 816 10 0 0 0 0 0 0
lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
-
established:建立的連線
-
close:close狀態的連線
-
close_wait:close_wait狀態的連線
-
time_wait:time_wait狀態的連線
-
……
$ cat net/tcp
sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
0: 0100007F:274C 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 10547 1 ffff880426cb0000 100 0 0 10 0
1: 00000000:0016 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 10616 1 ffff880426cb0780 100 0 0 10 0
2: 0100007F:0019 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 11239 1 ffff880426cb1680 100 0 0 10 0
3: 00000000:2742 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 19286 1 ffff880427900780 100 0 0 10 0
4: B42A020A:2742 D014020A:C683 06 00000000:00000000 03:00000CF2 00000000 0 0 0 3 ffff8804216c7d00
5: B42A020A:2742 D014020A:879D 06 00000000:00000000 03:00001259 00000000 0 0 0 3 ffff8804216c7e00
6: B42A020A:638C 3602030A:0885 01 00000000:00000000 00:00000000 00000000 0 0 64399466 1 ffff8804256fe180 20 4 30 10 -1
7: B42A020A:2742 D014020A:B04A 06 00000000:00000000 03:000016ED 00000000 0 0 0 3 ffff8804216c6500
8: B42A020A:2742 D014020A:CC0F 06 00000000:00000000 03:00000D61 00000000 0 0 0 3 ffff8804216c6800
9: B42A020A:688D 4C02030A:276A 01 00000000:00000000 00:00000000 00000000 0 0 64348606 1 ffff880426cb5280 20 4 30 10 12
10: B42A020A:2742 D014020A:AE80 06 00000000:00000000 03:00001688 00000000 0 0 0 3 ffff8804216c7000
11: B42A020A:DC39 3502030A:0885 01 00000000:00000000 00:00000000 00000000 0 0 63592428 2 ffff8804256fb480 20 4 30 10 -1
12: B42A020A:851F 4B02030A:276A 08 00000000:00000001 00:00000000 00000000 0 0 12895659 1 ffff8804220b4b00 20 4 28 10 7
"01": "established",
"02": "syn_sent",
"03": "syn_recv",
"04": "fin_wait1",
"05": "fin_wait2",
"06": "time_wait",
"07": "close",
"08": "close_wait",
"09": "last_ack",
"0A": "listen",
"0B": "closing",
"0C": "unknown",
-
used:磁碟使用量
-
used percent:磁碟使用率
`docker exec -i $CONTAINER_PID "df"|grep -v "tmpfs"`
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/docker-253:0-1049953-53ec5aa5f4a669b3a26b19cc2675f5537ba59014419e97324f703cb050152cc6
10475520 44496 10431024 0% /
tmpfs 98894428 0 98894428 0% /dev
tmpfs 98894428 0 98894428 0% /sys/fs/cgroup
/dev/mapper/VolGroup01-lv_root
279403540 38459756 226727800 15% /
/dev/mapper/VolGroup00-lv_root 279403540
38459756 226727800
17%
/
tmpfs 98894428 2384 98892044
782 99% /
/dev/mapper/VolGroup00-lv_root
279403540 38459756 226727800 15% /
/dev/mapper/VolGroup00-lv_root
279403540 38459756 226727800 15% /etc/hostname
/dev/mapper/VolGroup00-lv_root
279403540 38459756 226727800 15% /etc/hosts
shm 65536 0 65536 0% /dev/shm
tmpfs 98894428 0 98894428 0% /proc/kcore
tmpfs 98894428 0 98894428 0% /proc/timer_stats
tmpfs 98894428 0 98894428 0% /proc/sched_debug
attach
commit
copy
create
destroy
detach
die
exec_create
exec_detach
exec_start
export
health_status
kill
oom
pause
rename
resize
restart
start
stop
top
unpause
update
$ docker events --filter 'event=stop'
2018-03-06T00:40:22.880175420+08:00 container stop 0fdb...ff37 (image=alpine:latest, name=test)
2018-03-06T00:41:17.888104182+08:00 container stop 2a8f...4e78 (image=alpine, name=kickass_brattain)
-
cAdvisor:Google開發的容器監控指標採集,還支援聚合和一些資料處理;
-
Telegraf:Influxdata開發的收集Agent,這是一個通用的採集Agent,當然也支援Docker,另外該公司還提供了一整套監控方案叫做TICK,也歡迎大家去踩坑;
-
Prometheus:現在最火的Cloud方面的監控,而且是一整套的解決方案,包括告警、儲存等等;