aboutsummaryrefslogtreecommitdiff
path: root/collector/hwmon_linux.go
diff options
context:
space:
mode:
authorJonas Wielicki <jonas.wielicki@cloudandheat.com>2016-11-29 11:53:29 +0100
committerJonas Wielicki <j.wielicki@sotecware.net>2016-12-01 09:59:52 +0100
commitc481dd19dafcf463a2554ac07290cb33a50b617d (patch)
treec448ea5ace1dbc9b577a1cb711c85a959fae6e7c /collector/hwmon_linux.go
parent006d1c7922b765f458fe9b92ce646641bded0f52 (diff)
downloadprometheus_node_collector-c481dd19dafcf463a2554ac07290cb33a50b617d.tar.bz2
prometheus_node_collector-c481dd19dafcf463a2554ac07290cb33a50b617d.tar.xz
prometheus_node_collector-c481dd19dafcf463a2554ac07290cb33a50b617d.zip
Re-introduce human-readable chip types
The chip label generation has been changed in #334 to prefer the unique device path (e.g. the location on the PCI bus) due to #333. Here, a new annotation metric ``node_hwmon_chip_names`` is introduced which allows to link the unique chip sysfs path to a human-readable chip name which may not be unique among chip sysfs paths (for example, dual-slot systems have multiple chipType="coretemp" sensors). This allows to mitigate the downsides of the solution to #333 (namely that the device path may not be stable across kernels and reboots) for cases where it does not matter that multiple devices may have the same human-readable name (e.g. aggregation or where at most one device with a common chip name is present). For cases where no human-readable name can be derived, the annotation metric is not emitted.
Diffstat (limited to 'collector/hwmon_linux.go')
-rw-r--r--collector/hwmon_linux.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/collector/hwmon_linux.go b/collector/hwmon_linux.go
index d879aca..ef4b727 100644
--- a/collector/hwmon_linux.go
+++ b/collector/hwmon_linux.go
@@ -36,6 +36,7 @@ var (
36 hwmonInvalidMetricChars = regexp.MustCompile("[^a-z0-9:_]") 36 hwmonInvalidMetricChars = regexp.MustCompile("[^a-z0-9:_]")
37 hwmonFilenameFormat = regexp.MustCompile(`^(?P<type>[^0-9]+)(?P<id>[0-9]*)?(_(?P<property>.+))?$`) 37 hwmonFilenameFormat = regexp.MustCompile(`^(?P<type>[^0-9]+)(?P<id>[0-9]*)?(_(?P<property>.+))?$`)
38 hwmonLabelDesc = []string{"chip", "sensor"} 38 hwmonLabelDesc = []string{"chip", "sensor"}
39 hwmonChipNameLabelDesc = []string{"chip", "chip_name"}
39 hwmonSensorTypes = []string{ 40 hwmonSensorTypes = []string{
40 "vrm", "beep_enable", "update_interval", "in", "cpu", "fan", 41 "vrm", "beep_enable", "update_interval", "in", "cpu", "fan",
41 "pwm", "temp", "curr", "power", "energy", "humidity", 42 "pwm", "temp", "curr", "power", "energy", "humidity",
@@ -143,6 +144,26 @@ func (c *hwMonCollector) updateHwmon(ch chan<- prometheus.Metric, dir string) (e
143 } 144 }
144 } 145 }
145 146
147 hwmonChipName, err := c.hwmonHumanReadableChipName(dir)
148
149 if err == nil {
150 // sensor chip metadata
151 desc := prometheus.NewDesc(
152 "node_hwmon_chip_names",
153 "Annotation metric for human-readable chip names",
154 hwmonChipNameLabelDesc,
155 nil,
156 )
157
158 ch <- prometheus.MustNewConstMetric(
159 desc,
160 prometheus.GaugeValue,
161 1.0,
162 hwmonName,
163 hwmonChipName,
164 )
165 }
166
146 // format all sensors 167 // format all sensors
147 for sensor, sensorData := range data { 168 for sensor, sensorData := range data {
148 169
@@ -351,6 +372,27 @@ func (c *hwMonCollector) hwmonName(dir string) (string, error) {
351 return "", errors.New("Could not derive a monitoring name for " + dir) 372 return "", errors.New("Could not derive a monitoring name for " + dir)
352} 373}
353 374
375func (c *hwMonCollector) hwmonHumanReadableChipName(dir string) (string, error) {
376 // this is similar to the methods in hwmonName, but with different
377 // precedences -- we can allow duplicates here.
378
379 // preference 1: is there a name file
380
381 sysnameRaw, nameErr := ioutil.ReadFile(path.Join(dir, "name"))
382 if nameErr != nil {
383 return "", nameErr
384 }
385
386 if string(sysnameRaw) != "" {
387 cleanName := cleanMetricName(string(sysnameRaw))
388 if cleanName != "" {
389 return cleanName, nil
390 }
391 }
392
393 return "", errors.New("Could not derive a human-readable chip type for " + dir)
394}
395
354func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) (err error) { 396func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) (err error) {
355 // Step 1: scan /sys/class/hwmon, resolve all symlinks and call 397 // Step 1: scan /sys/class/hwmon, resolve all symlinks and call
356 // updatesHwmon for each folder 398 // updatesHwmon for each folder