Monitoring TcpState of docker container with ccadvisor influxdb grafana

Posted by dshevnock on Tue, 26 Nov 2019 18:10:52 +0100


After setting up the monitoring cluster of ccadvisor influxdb grafana, it is found that there is no tcp related data

Source version:
git commit hash:9db8c7dee20a0c41627b208977ab192a0411bf93

Build a cfisor influxdb grafana reference

Positioning process

Is there no tcp state recorded by cadviser?

It's easy to search, because of the high cpu usage of cadviser, it needs to -- Disable "metrics =" "
In fact, this is not the case
Start cadviser locally without any parameters
~/gopath/src/*) ยป sudo ./cadvisor -logtostderr
Open in browser : 8080/containers / you can see the response with TcpState

Is the influxdb written?

  1. Open the implux DB shell
InfluxDB shell
> show databases
name: databases
> use cadvisor
Using database cadvisor
> show tag keys
name: cpu_usage_system

As you can see, these tagkeys correspond to the select column in grafana
So, is cadviser not writing to influxdb?

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


You need to modify cadviser code and add the metrics you need

Topics: Linux InfluxDB network github Google