fix(content): harden Docker practice guide

This commit is contained in:
yeasy
2026-06-16 21:23:21 -07:00
parent f4e684afeb
commit 9fdffa9d91
67 changed files with 343 additions and 278 deletions
@@ -6,44 +6,18 @@
#### 核心性能指标体系
容器性能监控涉及以下关键指标
容器性能监控涉及 Docker CLIPrometheus/cAdvisor 指标和底层 cgroup 文件现代 Linux Kubernetes 新版本通常使用 cgroup v2旧系统或兼容环境仍可能看到 cgroup v1 名称
**CPU 相关指标**
- `cpu.usage_usec`容器 CPU 使用时间微秒
- `cpu.stat.nr_throttled`CPU 限流发生次数
- `cpu.stat.throttled_usec`CPU 限流总时间
- `cpu_percent`CPU 使用百分比
- `cpu_quota`CPU 配额设置微秒
**内存相关指标**
- `memory.usage_bytes`当前内存使用量
- `memory.max_usage_bytes`内存使用峰值
- `memory.limit_in_bytes`内存限制
- `memory.fail_cnt`OOMOut of Memory失败次数
- `memory.stat.cache`页面缓存占用
- `memory.stat.rss`实际内存占用RSS
- `memory.stat.swap`SWAP 使用量
**网络相关指标**
- `rx_bytes`接收字节数
- `tx_bytes`发送字节数
- `rx_packets`接收包数
- `tx_packets`发送包数
- `rx_errors`接收错误数
- `tx_errors`发送错误数
- `rx_dropped`接收丢包数
- `tx_dropped`发送丢包数
**I/O 相关指标**
- `io_service_bytes`I/O 操作字节数
- `io_service_time`I/O 操作耗时
- `io_queued`I/O 队列长度
- `fs_limit_bytes`文件系统限制
- `fs_usage_bytes`文件系统使用量
| 类型 | Docker / Prometheus 常见指标 | cgroup v2 文件 | cgroup v1 兼容名 |
|------|------------------------------|----------------|------------------|
| CPU 使用 | `CPU %``container_cpu_usage_seconds_total` | `cpu.stat` 中的 `usage_usec` | `cpuacct.usage` |
| CPU 限流 | `container_cpu_cfs_throttled_periods_total` | `cpu.stat` 中的 `nr_throttled``throttled_usec` | `cpu.stat.nr_throttled``cpu.stat.throttled_time` |
| 内存使用 | `MEM USAGE``container_memory_working_set_bytes` | `memory.current` | `memory.usage_in_bytes` |
| 内存限制 | `MEM USAGE / LIMIT` | `memory.max` | `memory.limit_in_bytes` |
| OOM 次数 | `container_oom_events_total` 或运行时事件 | `memory.events` 中的 `oom` / `oom_kill` | `memory.failcnt` |
| 网络收发 | `NET I/O``container_network_receive_bytes_total` / `transmit_bytes_total` | 网络命名空间接口计数 | `rx_bytes` / `tx_bytes` |
| I/O | `BLOCK I/O``container_fs_*` / `container_blkio_*` | `io.stat` | `blkio.throttle.io_service_bytes` |
| 文件系统 | `container_fs_usage_bytes` / `container_fs_limit_bytes` | 运行时或文件系统采集 | `fs_usage_bytes` / `fs_limit_bytes` |
### 19.3.2 使用 docker stats 实时监控
@@ -246,6 +220,16 @@ networks:
```
**Prometheus 配置文件prometheus.yml**
如果需要采集 Docker daemon 自身指标需要先在 Docker daemon 配置中开启 metrics
```json
{
"metrics-addr": "127.0.0.1:9323"
}
```
Prometheus 运行在容器里并使用 `host.docker.internal:9323` 抓取时daemon 必须监听容器可达的主机地址若改为 `0.0.0.0:9323`会把指标端口暴露给更大网络必须配合防火墙和可信网络边界
```yaml
global:
scrape_interval: 15s