Prefer device path based names over exported names (#334)

* Prefer device path based names over exported names

For some sensors (like coretemp) it is possible that multiple
instances exist, thus base the name on the device path and not on
the exported name.

* Update end-to-end test for dual socket machines

Explicitly have 2 coretemp instances with a symlink for the device
such that the hwmon collector must pick that name (or fail)
This commit is contained in:
Rene Treffer 2016-10-28 21:25:44 +02:00 committed by Brian Brazil
commit abe8e297a6
81 changed files with 159 additions and 111 deletions

View file

@ -306,22 +306,12 @@ func (c *hwMonCollector) hwmonName(dir string) (string, error) {
// human readable names would be bat0 or coretemp, while a path string
// could be platform_applesmc.768
// preference 1: is there a name file
sysnameRaw, nameErr := ioutil.ReadFile(path.Join(dir, "name"))
if nameErr == nil && string(sysnameRaw) != "" {
cleanName := cleanMetricName(string(sysnameRaw))
if cleanName != "" {
return cleanName, nil
}
}
// preference 2: construct a name based on device
// preference 1: construct a name based on device name, always unique
devicePath, devErr := filepath.EvalSymlinks(path.Join(dir, "device"))
if devErr == nil {
devPathPrefix, devName := path.Split(devicePath)
_, devType := path.Split(devPathPrefix)
_, devType := path.Split(strings.TrimRight(devPathPrefix, "/"))
cleanDevName := cleanMetricName(devName)
cleanDevType := cleanMetricName(devType)
@ -335,6 +325,15 @@ func (c *hwMonCollector) hwmonName(dir string) (string, error) {
}
}
// preference 2: is there a name file
sysnameRaw, nameErr := ioutil.ReadFile(path.Join(dir, "name"))
if nameErr == nil && string(sysnameRaw) != "" {
cleanName := cleanMetricName(string(sysnameRaw))
if cleanName != "" {
return cleanName, nil
}
}
// it looks bad, name and device don't provide enough information
// return a hwmon[0-9]* name