From 65394fe18c0b9df8e17ac96e2f24c0617d2288f7 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Tue, 20 Feb 2018 15:31:46 -0800 Subject: [PATCH] update cadvisor godeps and ignore per-cpu metrics --- Godeps/Godeps.json | 172 +++++++++--------- pkg/kubelet/cadvisor/cadvisor_linux.go | 6 +- .../google/cadvisor/container/factory.go | 1 + .../container/libcontainer/helpers.go | 15 +- .../google/cadvisor/metrics/prometheus.go | 10 +- 5 files changed, 110 insertions(+), 94 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index ca7de7c6ce2..8246c7d53be 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1454,218 +1454,218 @@ }, { "ImportPath": "github.com/google/cadvisor/accelerators", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/api", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/cache/memory", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/client/v2", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/collector", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/container", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/container/common", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/container/containerd", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/container/crio", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/container/docker", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/container/libcontainer", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/container/raw", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/container/rkt", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/container/systemd", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/devicemapper", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/events", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/fs", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/healthz", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/http", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/http/mux", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/info/v1", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/info/v2", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/machine", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/manager", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/manager/watcher", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/manager/watcher/raw", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/manager/watcher/rkt", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/metrics", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/pages", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/pages/static", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/storage", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/summary", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/utils", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/utils/cloudinfo", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/utils/cpuload", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/utils/cpuload/netlink", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/utils/docker", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/utils/oomparser", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/utils/sysfs", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/utils/sysinfo", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/validate", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/version", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/cadvisor/zfs", - "Comment": "v0.28.3-20-g6116f265", - "Rev": "6116f265302357cbb10f84737af30b1f13ce2d6c" + "Comment": "v0.29.0", + "Rev": "aaaa65dba02880718d0237cd4e80ab8eb278bb19" }, { "ImportPath": "github.com/google/certificate-transparency/go", diff --git a/pkg/kubelet/cadvisor/cadvisor_linux.go b/pkg/kubelet/cadvisor/cadvisor_linux.go index 6a6ef44c5d5..ffc2b0417be 100644 --- a/pkg/kubelet/cadvisor/cadvisor_linux.go +++ b/pkg/kubelet/cadvisor/cadvisor_linux.go @@ -108,7 +108,11 @@ func containerLabels(c *cadvisorapi.ContainerInfo) map[string]string { func New(address string, port uint, imageFsInfoProvider ImageFsInfoProvider, rootPath string, usingLegacyStats bool) (Interface, error) { sysFs := sysfs.NewRealSysFs() - ignoreMetrics := cadvisormetrics.MetricSet{cadvisormetrics.NetworkTcpUsageMetrics: struct{}{}, cadvisormetrics.NetworkUdpUsageMetrics: struct{}{}} + ignoreMetrics := cadvisormetrics.MetricSet{ + cadvisormetrics.NetworkTcpUsageMetrics: struct{}{}, + cadvisormetrics.NetworkUdpUsageMetrics: struct{}{}, + cadvisormetrics.PerCpuUsageMetrics: struct{}{}, + } if !usingLegacyStats { ignoreMetrics[cadvisormetrics.DiskUsageMetrics] = struct{}{} } diff --git a/vendor/github.com/google/cadvisor/container/factory.go b/vendor/github.com/google/cadvisor/container/factory.go index befb4a9e63c..07445f9dd70 100644 --- a/vendor/github.com/google/cadvisor/container/factory.go +++ b/vendor/github.com/google/cadvisor/container/factory.go @@ -42,6 +42,7 @@ type MetricKind string const ( CpuUsageMetrics MetricKind = "cpu" + PerCpuUsageMetrics MetricKind = "percpu" MemoryUsageMetrics MetricKind = "memory" CpuLoadMetrics MetricKind = "cpuLoad" DiskIOMetrics MetricKind = "diskIO" diff --git a/vendor/github.com/google/cadvisor/container/libcontainer/helpers.go b/vendor/github.com/google/cadvisor/container/libcontainer/helpers.go index c2194ac34ad..2f9270758b0 100644 --- a/vendor/github.com/google/cadvisor/container/libcontainer/helpers.go +++ b/vendor/github.com/google/cadvisor/container/libcontainer/helpers.go @@ -113,7 +113,8 @@ func GetStats(cgroupManager cgroups.Manager, rootFs string, pid int, ignoreMetri libcontainerStats := &libcontainer.Stats{ CgroupStats: cgroupStats, } - stats := newContainerStats(libcontainerStats) + withPerCPU := !ignoreMetrics.Has(container.PerCpuUsageMetrics) + stats := newContainerStats(libcontainerStats, withPerCPU) // If we know the pid then get network stats from /proc//net/dev if pid == 0 { @@ -467,14 +468,17 @@ func minUint32(x, y uint32) uint32 { var numCpusFunc = getNumberOnlineCPUs // Convert libcontainer stats to info.ContainerStats. -func setCpuStats(s *cgroups.Stats, ret *info.ContainerStats) { +func setCpuStats(s *cgroups.Stats, ret *info.ContainerStats, withPerCPU bool) { ret.Cpu.Usage.User = s.CpuStats.CpuUsage.UsageInUsermode ret.Cpu.Usage.System = s.CpuStats.CpuUsage.UsageInKernelmode - ret.Cpu.Usage.Total = 0 + ret.Cpu.Usage.Total = s.CpuStats.CpuUsage.TotalUsage ret.Cpu.CFS.Periods = s.CpuStats.ThrottlingData.Periods ret.Cpu.CFS.ThrottledPeriods = s.CpuStats.ThrottlingData.ThrottledPeriods ret.Cpu.CFS.ThrottledTime = s.CpuStats.ThrottlingData.ThrottledTime + if !withPerCPU { + return + } if len(s.CpuStats.CpuUsage.PercpuUsage) == 0 { // libcontainer's 'GetStats' can leave 'PercpuUsage' nil if it skipped the // cpuacct subsystem. @@ -501,7 +505,6 @@ func setCpuStats(s *cgroups.Stats, ret *info.ContainerStats) { for i := uint32(0); i < numActual; i++ { ret.Cpu.Usage.PerCpu[i] = s.CpuStats.CpuUsage.PercpuUsage[i] - ret.Cpu.Usage.Total += s.CpuStats.CpuUsage.PercpuUsage[i] } } @@ -587,13 +590,13 @@ func setNetworkStats(libcontainerStats *libcontainer.Stats, ret *info.ContainerS } } -func newContainerStats(libcontainerStats *libcontainer.Stats) *info.ContainerStats { +func newContainerStats(libcontainerStats *libcontainer.Stats, withPerCPU bool) *info.ContainerStats { ret := &info.ContainerStats{ Timestamp: time.Now(), } if s := libcontainerStats.CgroupStats; s != nil { - setCpuStats(s, ret) + setCpuStats(s, ret, withPerCPU) setDiskIoStats(s, ret) setMemoryStats(s, ret) } diff --git a/vendor/github.com/google/cadvisor/metrics/prometheus.go b/vendor/github.com/google/cadvisor/metrics/prometheus.go index 2dd7747b834..4354071b812 100644 --- a/vendor/github.com/google/cadvisor/metrics/prometheus.go +++ b/vendor/github.com/google/cadvisor/metrics/prometheus.go @@ -150,10 +150,18 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc) *PrometheusCo }, }, { name: "container_cpu_usage_seconds_total", - help: "Cumulative cpu time consumed per cpu in seconds.", + help: "Cumulative cpu time consumed in seconds.", valueType: prometheus.CounterValue, extraLabels: []string{"cpu"}, getValues: func(s *info.ContainerStats) metricValues { + if len(s.Cpu.Usage.PerCpu) == 0 { + if s.Cpu.Usage.Total > 0 { + return metricValues{{ + value: float64(s.Cpu.Usage.Total) / float64(time.Second), + labels: []string{"total"}, + }} + } + } values := make(metricValues, 0, len(s.Cpu.Usage.PerCpu)) for i, value := range s.Cpu.Usage.PerCpu { if value > 0 {