From b98cc7918446427e4b2de7b975c65c1f44451a56 Mon Sep 17 00:00:00 2001 From: bpopovschi Date: Mon, 16 Dec 2019 16:10:51 +0200 Subject: [PATCH 1/9] Added memory and cpu metrics for cgroupv2 Signed-off-by: bpopovschi --- cmd/ctr/commands/tasks/metrics.go | 14 ++++ metrics/cgroups/v2/cpu.go | 124 ++++++++++++++++++++++++++++++ metrics/cgroups/v2/memory.go | 92 ++++++++++++++++++++++ metrics/cgroups/v2/metrics.go | 2 + 4 files changed, 232 insertions(+) create mode 100644 metrics/cgroups/v2/cpu.go create mode 100644 metrics/cgroups/v2/memory.go diff --git a/cmd/ctr/commands/tasks/metrics.go b/cmd/ctr/commands/tasks/metrics.go index c980ced93..eb917ac95 100644 --- a/cmd/ctr/commands/tasks/metrics.go +++ b/cmd/ctr/commands/tasks/metrics.go @@ -152,6 +152,20 @@ func printCgroup2MetricsTable(w *tabwriter.Writer, data *v2.Metrics) { fmt.Fprintf(w, "pids.current\t%v\t\n", data.Pids.Current) fmt.Fprintf(w, "pids.limit\t%v\t\n", data.Pids.Limit) } + if data.CPU != nil { + fmt.Fprintf(w, "cpu.usage_usec\t%v\t\n", data.CPU.UsageUsec) + fmt.Fprintf(w, "cpu.user_usec\t%v\t\n", data.CPU.UserUsec) + fmt.Fprintf(w, "cpu.sys_usec\t%v\t\n", data.CPU.SystemUsec) + fmt.Fprintf(w, "cpu.number_of_periods\t%v\t\n", data.CPU.NrPeriods) + fmt.Fprintf(w, "cpu.number_of_throttled\t%v\t\n", data.CPU.NrThrottled) + fmt.Fprintf(w, "cpu.throttled_usec\t%v\t\n", data.CPU.ThrottledUsec) + } + if data.Memory != nil { + fmt.Fprintf(w, "memory.usage\t%v\t\n", data.Memory.Usage) + fmt.Fprintf(w, "memory.usage_limit\t%v\t\n", data.Memory.UsageLimit) + fmt.Fprintf(w, "memory.swap\t%v\t\n", data.Memory.SwapUsage) + fmt.Fprintf(w, "memory.swap_limit\t%v\t\n", data.Memory.SwapLimit) + } } func printWindowsContainerStatistics(w *tabwriter.Writer, stats *wstats.WindowsContainerStatistics) { diff --git a/metrics/cgroups/v2/cpu.go b/metrics/cgroups/v2/cpu.go new file mode 100644 index 000000000..bd8754b20 --- /dev/null +++ b/metrics/cgroups/v2/cpu.go @@ -0,0 +1,124 @@ +// +build linux + +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package v2 + +import ( + v2 "github.com/containerd/containerd/metrics/types/v2" + metrics "github.com/docker/go-metrics" + "github.com/prometheus/client_golang/prometheus" +) + +var cpuMetrics = []*metric{ + { + name: "cpu", + help: "Current cpu usage_usec (cgroup v2)", + unit: metrics.Unit("usage_usec"), + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.CPU == nil { + return nil + } + return []value{ + { + v: float64(stats.CPU.UsageUsec), + }, + } + }, + }, + { + name: "cpu", + help: "Current cpu user_usec (cgroup v2)", + unit: metrics.Unit("user_usec"), + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.CPU == nil { + return nil + } + return []value{ + { + v: float64(stats.CPU.UserUsec), + }, + } + }, + }, + { + name: "cpu", + help: "Current cpu system_usec (cgroup v2)", + unit: metrics.Unit("system_usec"), + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.CPU == nil { + return nil + } + return []value{ + { + v: float64(stats.CPU.SystemUsec), + }, + } + }, + }, + { + name: "cpu", + help: "Current cpu nr_periods (only if controller is enabled)", + unit: metrics.Unit("nr_periods"), + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.CPU == nil { + return nil + } + return []value{ + { + v: float64(stats.CPU.NrPeriods), + }, + } + }, + }, + { + name: "cpu", + help: "Current cpu nr_throttled (only if controller is enabled)", + unit: metrics.Unit("nr_throttled"), + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.CPU == nil { + return nil + } + return []value{ + { + v: float64(stats.CPU.NrThrottled), + }, + } + }, + }, + { + name: "cpu", + help: "Current cpu throttled_usec (only if controller is enabled)", + unit: metrics.Unit("throttled_usec"), + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.CPU == nil { + return nil + } + return []value{ + { + v: float64(stats.CPU.ThrottledUsec), + }, + } + }, + }, +} diff --git a/metrics/cgroups/v2/memory.go b/metrics/cgroups/v2/memory.go new file mode 100644 index 000000000..25c221bc0 --- /dev/null +++ b/metrics/cgroups/v2/memory.go @@ -0,0 +1,92 @@ +// +build linux + +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package v2 + +import ( + v2 "github.com/containerd/containerd/metrics/types/v2" + metrics "github.com/docker/go-metrics" + "github.com/prometheus/client_golang/prometheus" +) + +var memoryMetrics = []*metric{ + { + name: "memory", + help: "Current memory usage (cgroup v2)", + unit: metrics.Unit("usage"), + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.Usage), + }, + } + }, + }, + { + name: "memory", + help: "Current memory usage limit (cgroup v2)", + unit: metrics.Unit("limit"), + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.UsageLimit), + }, + } + }, + }, + { + name: "memory", + help: "Current swap usage (cgroup v2)", + unit: metrics.Unit("swap"), + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.SwapUsage), + }, + } + }, + }, + { + name: "memory", + help: "Current swap usage limit (cgroup v2)", + unit: metrics.Unit("swap_limit"), + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.SwapLimit), + }, + } + }, + }, +} diff --git a/metrics/cgroups/v2/metrics.go b/metrics/cgroups/v2/metrics.go index 134af9e62..bfb6f0553 100644 --- a/metrics/cgroups/v2/metrics.go +++ b/metrics/cgroups/v2/metrics.go @@ -43,6 +43,8 @@ func newCollector(ns *metrics.Namespace) *collector { tasks: make(map[string]runtime.Task), } c.metrics = append(c.metrics, pidMetrics...) + c.metrics = append(c.metrics, cpuMetrics...) + c.metrics = append(c.metrics, memoryMetrics...) c.storedMetrics = make(chan prometheus.Metric, 100*len(c.metrics)) ns.Add(c) return c From 6bfb24824b552cf09d8078750f565a0d72f8c711 Mon Sep 17 00:00:00 2001 From: bpopovschi Date: Mon, 16 Dec 2019 18:27:50 +0200 Subject: [PATCH 2/9] Fix prometheus metrics units Signed-off-by: bpopovschi --- metrics/cgroups/v2/cpu.go | 36 +-- metrics/cgroups/v2/memory.go | 513 ++++++++++++++++++++++++++++++++++- 2 files changed, 523 insertions(+), 26 deletions(-) diff --git a/metrics/cgroups/v2/cpu.go b/metrics/cgroups/v2/cpu.go index bd8754b20..ed93aef69 100644 --- a/metrics/cgroups/v2/cpu.go +++ b/metrics/cgroups/v2/cpu.go @@ -26,9 +26,9 @@ import ( var cpuMetrics = []*metric{ { - name: "cpu", - help: "Current cpu usage_usec (cgroup v2)", - unit: metrics.Unit("usage_usec"), + name: "cpu_usage", + help: "Total cpu usage (cgroup v2)", + unit: metrics.Nanoseconds, vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { if stats.CPU == nil { @@ -42,9 +42,9 @@ var cpuMetrics = []*metric{ }, }, { - name: "cpu", - help: "Current cpu user_usec (cgroup v2)", - unit: metrics.Unit("user_usec"), + name: "cpu_user_usage", + help: "Current cpu usage in user space (cgroup v2)", + unit: metrics.Nanoseconds, vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { if stats.CPU == nil { @@ -58,9 +58,9 @@ var cpuMetrics = []*metric{ }, }, { - name: "cpu", - help: "Current cpu system_usec (cgroup v2)", - unit: metrics.Unit("system_usec"), + name: "cpu_kernel_usage", + help: "Current cpu usage in kernel space (cgroup v2)", + unit: metrics.Nanoseconds, vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { if stats.CPU == nil { @@ -74,9 +74,9 @@ var cpuMetrics = []*metric{ }, }, { - name: "cpu", - help: "Current cpu nr_periods (only if controller is enabled)", - unit: metrics.Unit("nr_periods"), + name: "cpu_nr_periods", + help: "Current cpu number of periods (only if controller is enabled)", + unit: metrics.Total, vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { if stats.CPU == nil { @@ -90,9 +90,9 @@ var cpuMetrics = []*metric{ }, }, { - name: "cpu", - help: "Current cpu nr_throttled (only if controller is enabled)", - unit: metrics.Unit("nr_throttled"), + name: "cpu_nr_throttled", + help: "Total number of times tasks have been throttled (only if controller is enabled)", + unit: metrics.Total, vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { if stats.CPU == nil { @@ -106,9 +106,9 @@ var cpuMetrics = []*metric{ }, }, { - name: "cpu", - help: "Current cpu throttled_usec (only if controller is enabled)", - unit: metrics.Unit("throttled_usec"), + name: "cpu_throttled_usec", + help: "Total time duration for which tasks have been throttled. (only if controller is enabled)", + unit: metrics.Nanoseconds, vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { if stats.CPU == nil { diff --git a/metrics/cgroups/v2/memory.go b/metrics/cgroups/v2/memory.go index 25c221bc0..7b8996e77 100644 --- a/metrics/cgroups/v2/memory.go +++ b/metrics/cgroups/v2/memory.go @@ -26,9 +26,9 @@ import ( var memoryMetrics = []*metric{ { - name: "memory", + name: "memory_usage", help: "Current memory usage (cgroup v2)", - unit: metrics.Unit("usage"), + unit: metrics.Bytes, vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { if stats.Memory == nil { @@ -42,9 +42,9 @@ var memoryMetrics = []*metric{ }, }, { - name: "memory", + name: "memory_limit", help: "Current memory usage limit (cgroup v2)", - unit: metrics.Unit("limit"), + unit: metrics.Bytes, vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { if stats.Memory == nil { @@ -58,9 +58,9 @@ var memoryMetrics = []*metric{ }, }, { - name: "memory", + name: "memory_swap_usage", help: "Current swap usage (cgroup v2)", - unit: metrics.Unit("swap"), + unit: metrics.Bytes, vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { if stats.Memory == nil { @@ -74,9 +74,9 @@ var memoryMetrics = []*metric{ }, }, { - name: "memory", + name: "memory_swap_Limit", help: "Current swap usage limit (cgroup v2)", - unit: metrics.Unit("swap_limit"), + unit: metrics.Bytes, vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { if stats.Memory == nil { @@ -89,4 +89,501 @@ var memoryMetrics = []*metric{ } }, }, + + { + name: "memory_mapped_file", + help: "The mapped_file amount used", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.FileMapped), + }, + } + }, + }, + { + name: "memory_dirty_file", + help: "The dirty file amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.FileDirty), + }, + } + }, + }, + { + name: "memory_file_writeback", + help: "The file_writeback amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.FileWriteback), + }, + } + }, + }, + { + name: "memory_pgactive", + help: "The pgactive amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.Pgactivate), + }, + } + }, + }, + { + name: "memory_pgdeactivate", + help: "The pgdeactivate amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.Pgdeactivate), + }, + } + }, + }, + { + name: "memory_pgfault", + help: "The pgfault amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.Pgfault), + }, + } + }, + }, + { + name: "memory_pgmajfault", + help: "The pgmajfault amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.Pgmajfault), + }, + } + }, + }, + { + name: "memory_pglazyfree", + help: "The pglazyfree amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.Pglazyfree), + }, + } + }, + }, + { + name: "memory_pgrefill", + help: "The pgrefill amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.Pgrefill), + }, + } + }, + }, + { + name: "memory_pglazyfreed", + help: "The pglazyfreed amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.Pglazyfreed), + }, + } + }, + }, + { + name: "memory_pgscan", + help: "The pgscan amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.Pgscan), + }, + } + }, + }, + { + name: "memory_pgsteal", + help: "The pgsteal amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.Pgsteal), + }, + } + }, + }, + { + name: "memory_inactive_anon", + help: "The inactive_anon amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.InactiveAnon), + }, + } + }, + }, + { + name: "memory_active_anon", + help: "The active_anon amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.ActiveAnon), + }, + } + }, + }, + { + name: "memory_inactive_file", + help: "The inactive_file amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.InactiveFile), + }, + } + }, + }, + { + name: "memory_active_file", + help: "The active_file amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.ActiveFile), + }, + } + }, + }, + { + name: "memory_unevictable", + help: "The unevictable amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.Unevictable), + }, + } + }, + }, + { + name: "memory_anon", + help: "The anon amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.Anon), + }, + } + }, + }, + { + name: "memory_file", + help: "The file amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.File), + }, + } + }, + }, + { + name: "memory_kernel_stack", + help: "The kernel_stack amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.KernelStack), + }, + } + }, + }, + { + name: "memory_slab", + help: "The slab amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.Slab), + }, + } + }, + }, + { + name: "memory_sock", + help: "The sock amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.Sock), + }, + } + }, + }, + { + name: "memory_shmem", + help: "The shmem amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.Shmem), + }, + } + }, + }, + { + name: "memory_anon_thp", + help: "The anon_thp amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.AnonThp), + }, + } + }, + }, + { + name: "memory_slab_reclaimable", + help: "The slab_reclaimable amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.SlabReclaimable), + }, + } + }, + }, + { + name: "memory_slab_unreclaimable", + help: "The slab_unreclaimable amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.SlabUnreclaimable), + }, + } + }, + }, + { + name: "memory_workingset_refault", + help: "The workingset_refault amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.WorkingsetRefault), + }, + } + }, + }, + { + name: "memory_workingset_activate", + help: "The workingset_activate amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.WorkingsetActivate), + }, + } + }, + }, + { + name: "memory_workingset_nodereclaim", + help: "The workingset_nodereclaim amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.WorkingsetNodereclaim), + }, + } + }, + }, + { + name: "memory_thp_fault_alloc", + help: "The thp_fault_alloc amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.ThpFaultAlloc), + }, + } + }, + }, + { + name: "memory_thp_collapse_alloc", + help: "The thp_collapse_alloc amount", + unit: metrics.Bytes, + vt: prometheus.GaugeValue, + getValues: func(stats *v2.Metrics) []value { + if stats.Memory == nil { + return nil + } + return []value{ + { + v: float64(stats.Memory.ThpCollapseAlloc), + }, + } + }, + }, } From f287bc2292efadee8e4ed2092ae7c782e595cdbd Mon Sep 17 00:00:00 2001 From: bpopovschi Date: Mon, 16 Dec 2019 19:28:42 +0200 Subject: [PATCH 3/9] Schema names fix Signed-off-by: bpopovschi --- metrics/cgroups/v2/memory.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/metrics/cgroups/v2/memory.go b/metrics/cgroups/v2/memory.go index 7b8996e77..09a70c104 100644 --- a/metrics/cgroups/v2/memory.go +++ b/metrics/cgroups/v2/memory.go @@ -91,8 +91,8 @@ var memoryMetrics = []*metric{ }, { - name: "memory_mapped_file", - help: "The mapped_file amount used", + name: "memory_file_mapped", + help: "The file_mapped amount", unit: metrics.Bytes, vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { @@ -107,8 +107,8 @@ var memoryMetrics = []*metric{ }, }, { - name: "memory_dirty_file", - help: "The dirty file amount", + name: "memory_file_dirty", + help: "The file_dirty amount", unit: metrics.Bytes, vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { From 17d61d6b7e7ac55c9b8bd52d41606aeca8b6bd03 Mon Sep 17 00:00:00 2001 From: Boris Popovschi Date: Mon, 16 Dec 2019 19:54:21 +0200 Subject: [PATCH 4/9] Units fix Signed-off-by: Boris Popovschi --- metrics/cgroups/v2/cpu.go | 8 ++++---- metrics/cgroups/v2/memory.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/metrics/cgroups/v2/cpu.go b/metrics/cgroups/v2/cpu.go index ed93aef69..e35b96345 100644 --- a/metrics/cgroups/v2/cpu.go +++ b/metrics/cgroups/v2/cpu.go @@ -28,7 +28,7 @@ var cpuMetrics = []*metric{ { name: "cpu_usage", help: "Total cpu usage (cgroup v2)", - unit: metrics.Nanoseconds, + unit: metrics.Unit("microseconds"), vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { if stats.CPU == nil { @@ -44,7 +44,7 @@ var cpuMetrics = []*metric{ { name: "cpu_user_usage", help: "Current cpu usage in user space (cgroup v2)", - unit: metrics.Nanoseconds, + unit: metrics.Unit("microseconds"), vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { if stats.CPU == nil { @@ -60,7 +60,7 @@ var cpuMetrics = []*metric{ { name: "cpu_kernel_usage", help: "Current cpu usage in kernel space (cgroup v2)", - unit: metrics.Nanoseconds, + unit: metrics.Unit("microseconds"), vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { if stats.CPU == nil { @@ -108,7 +108,7 @@ var cpuMetrics = []*metric{ { name: "cpu_throttled_usec", help: "Total time duration for which tasks have been throttled. (only if controller is enabled)", - unit: metrics.Nanoseconds, + unit: metrics.Unit("microseconds"), vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { if stats.CPU == nil { diff --git a/metrics/cgroups/v2/memory.go b/metrics/cgroups/v2/memory.go index 09a70c104..647c83637 100644 --- a/metrics/cgroups/v2/memory.go +++ b/metrics/cgroups/v2/memory.go @@ -139,8 +139,8 @@ var memoryMetrics = []*metric{ }, }, { - name: "memory_pgactive", - help: "The pgactive amount", + name: "memory_pgactivate", + help: "The pgactivate amount", unit: metrics.Bytes, vt: prometheus.GaugeValue, getValues: func(stats *v2.Metrics) []value { From 23dbae3e71550e43b21c963f859dc7ecee444f8f Mon Sep 17 00:00:00 2001 From: Boris Popovschi Date: Tue, 17 Dec 2019 10:40:11 +0200 Subject: [PATCH 5/9] Schema name fix Signed-off-by: Boris Popovschi --- metrics/cgroups/v2/memory.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics/cgroups/v2/memory.go b/metrics/cgroups/v2/memory.go index 647c83637..52a6bc756 100644 --- a/metrics/cgroups/v2/memory.go +++ b/metrics/cgroups/v2/memory.go @@ -42,7 +42,7 @@ var memoryMetrics = []*metric{ }, }, { - name: "memory_limit", + name: "memory_usage_limit", help: "Current memory usage limit (cgroup v2)", unit: metrics.Bytes, vt: prometheus.GaugeValue, From 659c971cad1fa1c0e183e17e3349bb2270fa1a3a Mon Sep 17 00:00:00 2001 From: Boris Popovschi Date: Tue, 17 Dec 2019 10:52:37 +0200 Subject: [PATCH 6/9] task metrics fix Signed-off-by: Boris Popovschi --- cmd/ctr/commands/tasks/metrics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/ctr/commands/tasks/metrics.go b/cmd/ctr/commands/tasks/metrics.go index eb917ac95..69b968fbc 100644 --- a/cmd/ctr/commands/tasks/metrics.go +++ b/cmd/ctr/commands/tasks/metrics.go @@ -163,7 +163,7 @@ func printCgroup2MetricsTable(w *tabwriter.Writer, data *v2.Metrics) { if data.Memory != nil { fmt.Fprintf(w, "memory.usage\t%v\t\n", data.Memory.Usage) fmt.Fprintf(w, "memory.usage_limit\t%v\t\n", data.Memory.UsageLimit) - fmt.Fprintf(w, "memory.swap\t%v\t\n", data.Memory.SwapUsage) + fmt.Fprintf(w, "memory.swap_usage\t%v\t\n", data.Memory.SwapUsage) fmt.Fprintf(w, "memory.swap_limit\t%v\t\n", data.Memory.SwapLimit) } } From 929ab521c67e59a34983d9bffc513e1b20c3d647 Mon Sep 17 00:00:00 2001 From: Boris Popovschi Date: Tue, 17 Dec 2019 11:05:28 +0200 Subject: [PATCH 7/9] fix system usage naming Signed-off-by: Boris Popovschi --- metrics/cgroups/v2/cpu.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics/cgroups/v2/cpu.go b/metrics/cgroups/v2/cpu.go index e35b96345..d698d4d79 100644 --- a/metrics/cgroups/v2/cpu.go +++ b/metrics/cgroups/v2/cpu.go @@ -58,7 +58,7 @@ var cpuMetrics = []*metric{ }, }, { - name: "cpu_kernel_usage", + name: "cpu_system_usage", help: "Current cpu usage in kernel space (cgroup v2)", unit: metrics.Unit("microseconds"), vt: prometheus.GaugeValue, From b9d9bdf1fda27652035879082bd84aba43c4f6ac Mon Sep 17 00:00:00 2001 From: Boris Popovschi Date: Tue, 17 Dec 2019 12:22:55 +0200 Subject: [PATCH 8/9] make cpu metrics consistent with v2 docs Signed-off-by: Boris Popovschi --- metrics/cgroups/v2/cpu.go | 6 +++--- metrics/cgroups/v2/memory.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/metrics/cgroups/v2/cpu.go b/metrics/cgroups/v2/cpu.go index d698d4d79..c9a48ad33 100644 --- a/metrics/cgroups/v2/cpu.go +++ b/metrics/cgroups/v2/cpu.go @@ -26,7 +26,7 @@ import ( var cpuMetrics = []*metric{ { - name: "cpu_usage", + name: "cpu_usage_usec", help: "Total cpu usage (cgroup v2)", unit: metrics.Unit("microseconds"), vt: prometheus.GaugeValue, @@ -42,7 +42,7 @@ var cpuMetrics = []*metric{ }, }, { - name: "cpu_user_usage", + name: "cpu_user_usec", help: "Current cpu usage in user space (cgroup v2)", unit: metrics.Unit("microseconds"), vt: prometheus.GaugeValue, @@ -58,7 +58,7 @@ var cpuMetrics = []*metric{ }, }, { - name: "cpu_system_usage", + name: "cpu_system_usec", help: "Current cpu usage in kernel space (cgroup v2)", unit: metrics.Unit("microseconds"), vt: prometheus.GaugeValue, diff --git a/metrics/cgroups/v2/memory.go b/metrics/cgroups/v2/memory.go index 52a6bc756..e3869a3ea 100644 --- a/metrics/cgroups/v2/memory.go +++ b/metrics/cgroups/v2/memory.go @@ -74,7 +74,7 @@ var memoryMetrics = []*metric{ }, }, { - name: "memory_swap_Limit", + name: "memory_swap_limit", help: "Current swap usage limit (cgroup v2)", unit: metrics.Bytes, vt: prometheus.GaugeValue, From 49e7039a8501c0396d591471d40680402af2c784 Mon Sep 17 00:00:00 2001 From: Boris Popovschi Date: Tue, 17 Dec 2019 12:30:12 +0200 Subject: [PATCH 9/9] cpu metrics consistency Signed-off-by: Boris Popovschi --- cmd/ctr/commands/tasks/metrics.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/ctr/commands/tasks/metrics.go b/cmd/ctr/commands/tasks/metrics.go index 69b968fbc..263f183a3 100644 --- a/cmd/ctr/commands/tasks/metrics.go +++ b/cmd/ctr/commands/tasks/metrics.go @@ -155,9 +155,9 @@ func printCgroup2MetricsTable(w *tabwriter.Writer, data *v2.Metrics) { if data.CPU != nil { fmt.Fprintf(w, "cpu.usage_usec\t%v\t\n", data.CPU.UsageUsec) fmt.Fprintf(w, "cpu.user_usec\t%v\t\n", data.CPU.UserUsec) - fmt.Fprintf(w, "cpu.sys_usec\t%v\t\n", data.CPU.SystemUsec) - fmt.Fprintf(w, "cpu.number_of_periods\t%v\t\n", data.CPU.NrPeriods) - fmt.Fprintf(w, "cpu.number_of_throttled\t%v\t\n", data.CPU.NrThrottled) + fmt.Fprintf(w, "cpu.system_usec\t%v\t\n", data.CPU.SystemUsec) + fmt.Fprintf(w, "cpu.nr_periods\t%v\t\n", data.CPU.NrPeriods) + fmt.Fprintf(w, "cpu.nr_throttled\t%v\t\n", data.CPU.NrThrottled) fmt.Fprintf(w, "cpu.throttled_usec\t%v\t\n", data.CPU.ThrottledUsec) } if data.Memory != nil {