1. cAdvisor简介
cAdvisor对Node机器上的资源及容器进行实时监控和性能数据采集,包括CPU使用情况、内存使用情况、网络吞吐量及文件系统使用情况,cAdvisor集成在Kubelet中,当kubelet启动时会自动启动cAdvisor,即一个cAdvisor仅对一台Node机器进行监控。kubelet的启动参数–cadvisor-port可以定义cAdvisor对外提供服务的端口,默认为4194。可以通过浏览器<Node_IP:port>访问。项目主页:http://github.com/google/cadvisor。
2. cAdvisor结构图
3. Metrics
分类 | 字段 | 描述 |
---|---|---|
cpu | cpu_usage_total | |
cpu_usage_system | ||
cpu_usage_user | ||
cpu_usage_per_cpu | ||
load_average | Smoothed average of number of runnable threads x 1000 | |
memory | memory_usage | Memory Usage |
memory_working_set | Working set size | |
network | rx_bytes | Cumulative count of bytes received |
rx_errors | Cumulative count of receive errors encountered | |
tx_bytes | Cumulative count of bytes transmitted | |
tx_errors | Cumulative count of transmit errors encountered | |
filesystem | fs_device | Filesystem device |
fs_limit | Filesystem limit | |
fs_usage | Filesystem usage |
4. cAdvisor源码
4.1. cAdvisor入口函数
cadvisor.go
1 | func main() { |
核心代码:
1 | memoryStorage, err := NewMemoryStorage() |
4.2. cAdvisor Client的使用
1 | import "github.com/google/cadvisor/client" |
4.2.1 client定义
cadvisor/client/client.go
1 | // Client represents the base URL for a cAdvisor client. |
4.2.2. client方法
1)MachineInfo
1 | // MachineInfo returns the JSON machine information for this client. |
2)ContainerInfo
1 | // ContainerInfo returns the JSON container information for the specified |
3)DockerContainer
1 | // Returns the JSON container information for the specified |
4)AllDockerContainers
1 | // Returns the JSON container information for all Docker containers. |