Skip to content

Commit

Permalink
collect flag_info and bug_info only for one core (#2156)
Browse files Browse the repository at this point in the history
Signed-off-by: binjip978 <binjip978@gmail.com>
  • Loading branch information
Sergei Semenchuk committed Sep 28, 2021
1 parent 2b490d6 commit 5de46c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions collector/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -167,14 +167,18 @@ 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
}
if err := updateFieldInfo(cpu.Bugs, c.cpuBugsIncludeRegexp, c.cpuBugsInfo, ch); err != nil {
return err
}
}

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions collector/fixtures/e2e-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5de46c6

Please sign in to comment.