Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only report core throttles per core, not per cpu #836

Merged
merged 5 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions collector/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"path/filepath"
"regexp"
"strconv"
"strings"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -70,11 +71,10 @@ func NewCPUCollector() (Collector, error) {
"Maximum cpu thread frequency in hertz.",
[]string{"cpu"}, nil,
),
// FIXME: This should be a per core metric, not per cpu!
cpuCoreThrottle: prometheus.NewDesc(
prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "core_throttles_total"),
"Number of times this cpu core has been throttled.",
[]string{"cpu"}, nil,
[]string{"core"}, nil,
),
cpuPackageThrottle: prometheus.NewDesc(
prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "package_throttles_total"),
Expand Down Expand Up @@ -104,11 +104,20 @@ func (c *cpuCollector) updateCPUfreq(ch chan<- prometheus.Metric) error {

var value uint64

cpu_core_throttles := make(map[int]uint64)

// cpu loop
for _, cpu := range cpus {
_, cpuName := filepath.Split(cpu)
cpuNum := strings.TrimPrefix(cpuName, "cpu")

core_id := -1
if value, err := readUintFromFile(filepath.Join(cpu, "topology/core_id")); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we only need core_id for thermal throttles, let's move this read to after we check for thermal throttles. Then we can avoid the -1 handling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it to an outer if as there is no need to read thermal throttles if we don't have the core_id.

CI is running....

log.Debugf("CPU %v is misssing topology/core_id", cpu)
} else {
core_id = int(value)
}

if _, err := os.Stat(filepath.Join(cpu, "cpufreq")); os.IsNotExist(err) {
log.Debugf("CPU %v is missing cpufreq", cpu)
} else {
Expand Down Expand Up @@ -137,7 +146,14 @@ func (c *cpuCollector) updateCPUfreq(ch chan<- prometheus.Metric) error {
if value, err = readUintFromFile(filepath.Join(cpu, "thermal_throttle", "core_throttle_count")); err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(c.cpuCoreThrottle, prometheus.CounterValue, float64(value), cpuNum)
if core_id != -1 {
cpu_core_throttles[core_id] = value
}
}

// core throttles
for core_id, value := range cpu_core_throttles {
ch <- prometheus.MustNewConstMetric(c.cpuCoreThrottle, prometheus.CounterValue, float64(value), strconv.Itoa(core_id))
}

nodes, err := filepath.Glob(sysFilePath("bus/node/devices/node[0-9]*"))
Expand Down
5 changes: 2 additions & 3 deletions collector/fixtures/e2e-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,8 @@ node_buddyinfo_blocks{node="0",size="9",zone="Normal"} 0
node_context_switches_total 3.8014093e+07
# HELP node_cpu_core_throttles_total Number of times this cpu core has been throttled.
# TYPE node_cpu_core_throttles_total counter
node_cpu_core_throttles_total{cpu="0"} 5
node_cpu_core_throttles_total{cpu="1"} 0
node_cpu_core_throttles_total{cpu="2"} 40
node_cpu_core_throttles_total{core="0"} 5
node_cpu_core_throttles_total{core="1"} 0
# HELP node_cpu_frequency_hertz Current cpu thread frequency in hertz.
# TYPE node_cpu_frequency_hertz gauge
node_cpu_frequency_hertz{cpu="0"} 1.699981e+09
Expand Down
34 changes: 33 additions & 1 deletion collector/fixtures/sys.ttar
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ Lines: 1
30
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/bus/cpu/devices/cpu0/topology
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/bus/cpu/devices/cpu0/topology/core_id
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/bus/cpu/devices/cpu1
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -79,6 +87,14 @@ Lines: 1
30
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/bus/cpu/devices/cpu1/topology
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/bus/cpu/devices/cpu1/topology/core_id
Lines: 1
1
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/bus/cpu/devices/cpu2
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand All @@ -87,14 +103,22 @@ Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/bus/cpu/devices/cpu2/thermal_throttle/core_throttle_count
Lines: 1
40
5
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/bus/cpu/devices/cpu2/thermal_throttle/package_throttle_count
Lines: 1
6
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/bus/cpu/devices/cpu2/topology
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/bus/cpu/devices/cpu2/topology/core_id
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/bus/cpu/devices/cpu3
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand All @@ -116,6 +140,14 @@ Lines: 1
1000
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/bus/cpu/devices/cpu3/topology
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/bus/cpu/devices/cpu3/topology/core_id
Lines: 1
1
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/bus/node
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down