From 5de46c6bac422263a050f652b931628f513a868a Mon Sep 17 00:00:00 2001 From: Sergei Semenchuk Date: Tue, 28 Sep 2021 08:44:03 +0300 Subject: [PATCH] collect flag_info and bug_info only for one core (#2156) 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 cbd8f71d..6918f116 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 ac254b5c..f892b839 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