用cAdvisor InfluxDB Grafana监控docker容器的TcpState

33次阅读

共计 2117 个字符,预计需要花费 6 分钟才能阅读完成。

问题
搭建完 cAdvisor InfluxDB Grafana 监控集群后, 发现没有 tcp 相关的数据.
源码版本:
https://github.com/google/cad…git commit hash:9db8c7dee20a0c41627b208977ab192a0411bf93
搭建 cAdvisor InfluxDB Grafana 参考
https://botleg.com/stories/mo…
定位过程
是否 cadvisor 没有记录 tcp state?
容易搜索到, 因为 cadvisor 的高 cpu 占用, 需要 –disable_metrics=””https://github.com/google/cad… 实际上并非如此. 不带任何参数情况下, 本地启动 cadvisor.~/gopath/src/github.com/google/cadvisor(master*) » sudo ./cadvisor -logtostderr 在浏览器中打开 http://127.0.0.1:8080/containers/ 可以看到 response 中, 带有 TcpState.
是否写入了 influxdb?
打开 influx db shell
InfluxDB shell 0.9.6.1
> show databases
name: databases
—————
name
_internal
mydb
cadvisor
> use cadvisor
Using database cadvisor
> show tag keys
name: cpu_usage_system
———————-
tagKey
container_name
machine
可以看到, 这些 tagKey 对应 grafana 中的 select column. 那么, 是否 cadvisor 没有写入 influxdb 呢?cadvisor/storage/influxdb/influxdb.go:174
func (self *influxdbStorage) containerStatsToPoints(
cInfo *info.ContainerInfo,
stats *info.ContainerStats,
) (points []*influxdb.Point) {
// CPU usage: Total usage in nanoseconds
points = append(points, makePoint(serCpuUsageTotal, stats.Cpu.Usage.Total))

// CPU usage: Time spend in system space (in nanoseconds)
points = append(points, makePoint(serCpuUsageSystem, stats.Cpu.Usage.System))

// CPU usage: Time spent in user space (in nanoseconds)
points = append(points, makePoint(serCpuUsageUser, stats.Cpu.Usage.User))

// CPU usage per CPU
for i := 0; i < len(stats.Cpu.Usage.PerCpu); i++ {
point := makePoint(serCpuUsagePerCpu, stats.Cpu.Usage.PerCpu[i])
tags := map[string]string{“instance”: fmt.Sprintf(“%v”, i)}
addTagsToPoint(point, tags)

points = append(points, point)
}

// Load Average
points = append(points, makePoint(serLoadAverage, stats.Cpu.LoadAverage))

// Memory Usage
points = append(points, makePoint(serMemoryUsage, stats.Memory.Usage))

// Working Set Size
points = append(points, makePoint(serMemoryWorkingSet, stats.Memory.WorkingSet))

// Network Stats
points = append(points, makePoint(serRxBytes, stats.Network.RxBytes))
points = append(points, makePoint(serRxErrors, stats.Network.RxErrors))
points = append(points, makePoint(serTxBytes, stats.Network.TxBytes))
points = append(points, makePoint(serTxErrors, stats.Network.TxErrors))

self.tagPoints(cInfo, stats, points)

return points
}
结论
需要修改 cadvisor 代码, 将自己需要的 metrics 加上.

正文完
 0