Auto-sync: 2026-04-22 04:02
This commit is contained in:
67
wiki/entities/cAdvisor.md
Normal file
67
wiki/entities/cAdvisor.md
Normal file
@@ -0,0 +1,67 @@
|
||||
---
|
||||
title: "cAdvisor"
|
||||
type: entity
|
||||
aliases: [cAdvisor, Container Advisor, Google cAdvisor]
|
||||
tags: [monitoring, container, docker, prometheus, kubernetes]
|
||||
date: 2025-11-11
|
||||
---
|
||||
|
||||
# cAdvisor
|
||||
|
||||
## Overview
|
||||
cAdvisor(Container Advisor)是 Google 开源的容器资源监控工具,专门为 Docker 容器提供资源使用和性能指标的采集。它能自动发现机器上运行的所有容器,收集包括 CPU、内存、网络、磁盘 I/O 在内的各项资源指标,并暴露 Prometheus 格式的 `/metrics` 端点。
|
||||
|
||||
## Key Characteristics
|
||||
- **自动发现**:自动发现并监控机器上所有 Docker 容器,无需手动配置
|
||||
- **容器层级指标**:单容器粒度的资源使用数据
|
||||
- **历史数据**:支持容器级别的资源历史趋势
|
||||
- **Docker Socket 依赖**:需要挂载 `/var/run/docker.sock` 访问容器运行时信息
|
||||
|
||||
## Key Metrics Collected
|
||||
| 分类 | 指标前缀 | 说明 |
|
||||
|------|----------|------|
|
||||
| CPU | `container_cpu_usage_seconds_total` | 容器 CPU 使用时间 |
|
||||
| 内存 | `container_memory_usage_bytes` | 容器内存使用量 |
|
||||
| 网络 | `container_network_receive_bytes_total` | 网络接收字节 |
|
||||
| 磁盘 | `container_fs_reads_bytes_total` | 磁盘读取字节 |
|
||||
| 进程 | `container_tasks` | 容器内任务/进程数 |
|
||||
| 重启 | `container_restart_count` | 容器重启次数 |
|
||||
| 资源限制 | `container_spec_memory_limit_bytes` | 内存限制值 |
|
||||
|
||||
## Home Server Deployment
|
||||
```yaml
|
||||
# docker-compose.yml 片段
|
||||
cadvisor:
|
||||
image: gcr.io/cadvisor/cadvisor:latest
|
||||
container_name: cadvisor
|
||||
restart: always
|
||||
ports:
|
||||
- "8080:8080" # 暴露 metrics 端点
|
||||
volumes:
|
||||
- /:/rootfs:ro # 根文件系统
|
||||
- /var/run:/var/run:ro # Docker socket 目录
|
||||
- /sys:/sys:ro
|
||||
- /var/lib/docker/:/var/lib/docker:ro # Docker 存储
|
||||
```
|
||||
|
||||
> ⚠️ **安全注意**:挂载 Docker socket(`/var/run/docker.sock`)授予容器等同于宿主机 root 的权限。审慎评估风险,仅在内网可信环境中使用。
|
||||
|
||||
## Prometheus scrape_config
|
||||
```yaml
|
||||
- job_name: 'cadvisor'
|
||||
static_configs:
|
||||
- targets: ['cadvisor:8080']
|
||||
```
|
||||
|
||||
## Related Sources
|
||||
- [[家庭监控方案-prometheus-grafana-node-exporter-cadvisor-blackbox]]
|
||||
|
||||
## Related Entities
|
||||
- [[Prometheus]] — 数据消费者
|
||||
- [[Docker]] — 容器运行时依赖
|
||||
- [[node_exporter]] — 互补的主机层指标
|
||||
|
||||
## Related Concepts
|
||||
- [[Exporter]] — Prometheus 生态组件
|
||||
- [[容器资源限制]] — 容器 OOM / CPU 限制配置
|
||||
- [[System Monitoring]] — 应用领域
|
||||
Reference in New Issue
Block a user