From be37551c3190dc41d32ef17160c08dfe03583546 Mon Sep 17 00:00:00 2001 From: binjip978 Date: Mon, 27 Sep 2021 16:05:38 +0300 Subject: [PATCH] collect flag_info and bug_info only for one core Signed-off-by: binjip978 --- collector/cpu_linux.go | 8 ++++++-- collector/fixtures/e2e-output.txt | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/collector/cpu_linux.go b/collector/cpu_linux.go index cbd8f71d9b..6918f1168d 100644 --- a/collector/cpu_linux.go +++ b/collector/cpu_linux.go @@ -77,12 +77,12 @@ func NewCPUCollector(logger log.Logger) (Collector, error) { ), cpuFlagsInfo: prometheus.NewDesc( prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "flag_info"), - "The `flags` field of CPU information from /proc/cpuinfo.", + "The `flags` field of CPU information from /proc/cpuinfo taken from the first core.", []string{"flag"}, nil, ), cpuBugsInfo: prometheus.NewDesc( prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "bug_info"), - "The `bugs` field of CPU information from /proc/cpuinfo.", + "The `bugs` field of CPU information from /proc/cpuinfo taken from the first core.", []string{"bug"}, nil, ), cpuGuest: prometheus.NewDesc( @@ -167,7 +167,10 @@ func (c *cpuCollector) updateInfo(ch chan<- prometheus.Metric) error { cpu.Microcode, cpu.Stepping, cpu.CacheSize) + } + if len(info) != 0 { + cpu := info[0] if err := updateFieldInfo(cpu.Flags, c.cpuFlagsIncludeRegexp, c.cpuFlagsInfo, ch); err != nil { return err } @@ -175,6 +178,7 @@ func (c *cpuCollector) updateInfo(ch chan<- prometheus.Metric) error { return err } } + return nil } diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index c24d6a7071..b90942c46e 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -247,7 +247,7 @@ node_cooling_device_cur_state{name="0",type="Processor"} 0 # HELP node_cooling_device_max_state Maximum throttle state of the cooling device # TYPE node_cooling_device_max_state gauge node_cooling_device_max_state{name="0",type="Processor"} 3 -# HELP node_cpu_bug_info The `bugs` field of CPU information from /proc/cpuinfo. +# HELP node_cpu_bug_info The `bugs` field of CPU information from /proc/cpuinfo taken from the first core. # TYPE node_cpu_bug_info gauge node_cpu_bug_info{bug="cpu_meltdown"} 1 node_cpu_bug_info{bug="mds"} 1 @@ -259,7 +259,7 @@ node_cpu_core_throttles_total{core="0",package="0"} 5 node_cpu_core_throttles_total{core="0",package="1"} 0 node_cpu_core_throttles_total{core="1",package="0"} 0 node_cpu_core_throttles_total{core="1",package="1"} 9 -# HELP node_cpu_flag_info The `flags` field of CPU information from /proc/cpuinfo. +# HELP node_cpu_flag_info The `flags` field of CPU information from /proc/cpuinfo taken from the first core. # TYPE node_cpu_flag_info gauge node_cpu_flag_info{flag="aes"} 1 node_cpu_flag_info{flag="avx"} 1