用cAdvisor InfluxDB Grafana监控docker容器的TcpState

栏目: 服务器 · 发布时间: 5年前

内容简介:搭建完cAdvisor InfluxDB Grafana监控集群后, 发现没有tcp相关的数据.

问题

搭建完cAdvisor InfluxDB Grafana监控集群后, 发现没有tcp相关的数据.

用cAdvisor InfluxDB Grafana监控 <a href='https://www.codercto.com/topics/20577.html'>docker</a> 容器的TcpState

源码版本:

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.

用cAdvisor InfluxDB Grafana监控docker容器的TcpState

是否写入了influxdb?

  1. 打开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加上.


以上所述就是小编给大家介绍的《用cAdvisor InfluxDB Grafana监控docker容器的TcpState》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Compilers

Compilers

Alfred V. Aho、Monica S. Lam、Ravi Sethi、Jeffrey D. Ullman / Addison Wesley / 2006-9-10 / USD 186.80

This book provides the foundation for understanding the theory and pracitce of compilers. Revised and updated, it reflects the current state of compilation. Every chapter has been completely revised ......一起来看看 《Compilers》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具