aboutsummaryrefslogtreecommitdiff
path: root/collector/cpu_linux.go
diff options
context:
space:
mode:
authorRene Treffer <treffer+github@measite.de>2018-02-27 19:43:15 +0100
committerBen Kochie <superq@gmail.com>2018-02-27 19:43:15 +0100
commitc504c7e2649aec533678cc83d65230f4237a0c04 (patch)
tree1044ef9e4ab25dcd1d537af1740dd4001166678e /collector/cpu_linux.go
parent79ae03c4c7315eeebab360bceb6ac16722265418 (diff)
downloadprometheus_node_collector-c504c7e2649aec533678cc83d65230f4237a0c04.tar.bz2
prometheus_node_collector-c504c7e2649aec533678cc83d65230f4237a0c04.tar.xz
prometheus_node_collector-c504c7e2649aec533678cc83d65230f4237a0c04.zip
Only report core throttles per core, not per cpu (#836)
* Only report core throttles per core, not per cpu * Add topology/core_id to the cpu sysfs fixtures * Add new cpu fixtures to ttar file * Merge core_id reading and thermal throttle accounting * Declare core_id
Diffstat (limited to 'collector/cpu_linux.go')
-rw-r--r--collector/cpu_linux.go23
1 files changed, 18 insertions, 5 deletions
diff --git a/collector/cpu_linux.go b/collector/cpu_linux.go
index 4baf0ee..cd18bd9 100644
--- a/collector/cpu_linux.go
+++ b/collector/cpu_linux.go
@@ -21,6 +21,7 @@ import (
21 "os" 21 "os"
22 "path/filepath" 22 "path/filepath"
23 "regexp" 23 "regexp"
24 "strconv"
24 "strings" 25 "strings"
25 26
26 "github.com/prometheus/client_golang/prometheus" 27 "github.com/prometheus/client_golang/prometheus"
@@ -70,11 +71,10 @@ func NewCPUCollector() (Collector, error) {
70 "Maximum cpu thread frequency in hertz.", 71 "Maximum cpu thread frequency in hertz.",
71 []string{"cpu"}, nil, 72 []string{"cpu"}, nil,
72 ), 73 ),
73 // FIXME: This should be a per core metric, not per cpu!
74 cpuCoreThrottle: prometheus.NewDesc( 74 cpuCoreThrottle: prometheus.NewDesc(
75 prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "core_throttles_total"), 75 prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "core_throttles_total"),
76 "Number of times this cpu core has been throttled.", 76 "Number of times this cpu core has been throttled.",
77 []string{"cpu"}, nil, 77 []string{"core"}, nil,
78 ), 78 ),
79 cpuPackageThrottle: prometheus.NewDesc( 79 cpuPackageThrottle: prometheus.NewDesc(
80 prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "package_throttles_total"), 80 prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "package_throttles_total"),
@@ -104,6 +104,8 @@ func (c *cpuCollector) updateCPUfreq(ch chan<- prometheus.Metric) error {
104 104
105 var value uint64 105 var value uint64
106 106
107 cpu_core_throttles := make(map[int]uint64)
108
107 // cpu loop 109 // cpu loop
108 for _, cpu := range cpus { 110 for _, cpu := range cpus {
109 _, cpuName := filepath.Split(cpu) 111 _, cpuName := filepath.Split(cpu)
@@ -134,10 +136,21 @@ func (c *cpuCollector) updateCPUfreq(ch chan<- prometheus.Metric) error {
134 log.Debugf("CPU %v is missing thermal_throttle", cpu) 136 log.Debugf("CPU %v is missing thermal_throttle", cpu)
135 continue 137 continue
136 } 138 }
137 if value, err = readUintFromFile(filepath.Join(cpu, "thermal_throttle", "core_throttle_count")); err != nil { 139
138 return err 140 if value, err := readUintFromFile(filepath.Join(cpu, "topology/core_id")); err != nil {
141 log.Debugf("CPU %v is misssing topology/core_id", cpu)
142 } else {
143 core_id := int(value)
144 if value, err = readUintFromFile(filepath.Join(cpu, "thermal_throttle", "core_throttle_count")); err != nil {
145 return err
146 }
147 cpu_core_throttles[core_id] = value
139 } 148 }
140 ch <- prometheus.MustNewConstMetric(c.cpuCoreThrottle, prometheus.CounterValue, float64(value), cpuNum) 149 }
150
151 // core throttles
152 for core_id, value := range cpu_core_throttles {
153 ch <- prometheus.MustNewConstMetric(c.cpuCoreThrottle, prometheus.CounterValue, float64(value), strconv.Itoa(core_id))
141 } 154 }
142 155
143 nodes, err := filepath.Glob(sysFilePath("bus/node/devices/node[0-9]*")) 156 nodes, err := filepath.Glob(sysFilePath("bus/node/devices/node[0-9]*"))