@ -19,7 +19,6 @@ import (
"errors"
"errors"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path"
"path/filepath"
"path/filepath"
"regexp"
"regexp"
"strconv"
"strconv"
@ -138,7 +137,7 @@ func collectSensorData(dir string, data map[string]map[string]string) error {
for _ , t := range hwmonSensorTypes {
for _ , t := range hwmonSensorTypes {
if t == sensorType {
if t == sensorType {
addValueFile ( data , sensorType + strconv . Itoa ( sensorNum ) , sensorProperty , path. Join ( dir , file . Name ( ) ) )
addValueFile ( data , sensorType + strconv . Itoa ( sensorNum ) , sensorProperty , file path. Join ( dir , file . Name ( ) ) )
break
break
}
}
}
}
@ -157,8 +156,8 @@ func (c *hwMonCollector) updateHwmon(ch chan<- prometheus.Metric, dir string) er
if err != nil {
if err != nil {
return err
return err
}
}
if _ , err := os . Stat ( path. Join ( dir , "device" ) ) ; err == nil {
if _ , err := os . Stat ( file path. Join ( dir , "device" ) ) ; err == nil {
err := collectSensorData ( path. Join ( dir , "device" ) , data )
err := collectSensorData ( file path. Join ( dir , "device" ) , data )
if err != nil {
if err != nil {
return err
return err
}
}
@ -353,10 +352,10 @@ func (c *hwMonCollector) hwmonName(dir string) (string, error) {
// preference 1: construct a name based on device name, always unique
// preference 1: construct a name based on device name, always unique
devicePath , devErr := filepath . EvalSymlinks ( path. Join ( dir , "device" ) )
devicePath , devErr := filepath . EvalSymlinks ( file path. Join ( dir , "device" ) )
if devErr == nil {
if devErr == nil {
devPathPrefix , devName := path. Split ( devicePath )
devPathPrefix , devName := file path. Split ( devicePath )
_ , devType := path. Split ( strings . TrimRight ( devPathPrefix , "/" ) )
_ , devType := file path. Split ( strings . TrimRight ( devPathPrefix , "/" ) )
cleanDevName := cleanMetricName ( devName )
cleanDevName := cleanMetricName ( devName )
cleanDevType := cleanMetricName ( devType )
cleanDevType := cleanMetricName ( devType )
@ -371,7 +370,7 @@ func (c *hwMonCollector) hwmonName(dir string) (string, error) {
}
}
// preference 2: is there a name file
// preference 2: is there a name file
sysnameRaw , nameErr := ioutil . ReadFile ( path. Join ( dir , "name" ) )
sysnameRaw , nameErr := ioutil . ReadFile ( file path. Join ( dir , "name" ) )
if nameErr == nil && string ( sysnameRaw ) != "" {
if nameErr == nil && string ( sysnameRaw ) != "" {
cleanName := cleanMetricName ( string ( sysnameRaw ) )
cleanName := cleanMetricName ( string ( sysnameRaw ) )
if cleanName != "" {
if cleanName != "" {
@ -388,7 +387,7 @@ func (c *hwMonCollector) hwmonName(dir string) (string, error) {
}
}
// take the last path element, this will be hwmonX
// take the last path element, this will be hwmonX
_ , name := path. Split ( realDir )
_ , name := file path. Split ( realDir )
cleanName := cleanMetricName ( name )
cleanName := cleanMetricName ( name )
if cleanName != "" {
if cleanName != "" {
return cleanName , nil
return cleanName , nil
@ -399,7 +398,7 @@ func (c *hwMonCollector) hwmonName(dir string) (string, error) {
// hwmonHumanReadableChipName is similar to the methods in hwmonName, but with
// hwmonHumanReadableChipName is similar to the methods in hwmonName, but with
// different precedences -- we can allow duplicates here.
// different precedences -- we can allow duplicates here.
func ( c * hwMonCollector ) hwmonHumanReadableChipName ( dir string ) ( string , error ) {
func ( c * hwMonCollector ) hwmonHumanReadableChipName ( dir string ) ( string , error ) {
sysnameRaw , nameErr := ioutil . ReadFile ( path. Join ( dir , "name" ) )
sysnameRaw , nameErr := ioutil . ReadFile ( file path. Join ( dir , "name" ) )
if nameErr != nil {
if nameErr != nil {
return "" , nameErr
return "" , nameErr
}
}
@ -418,7 +417,7 @@ func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) error {
// Step 1: scan /sys/class/hwmon, resolve all symlinks and call
// Step 1: scan /sys/class/hwmon, resolve all symlinks and call
// updatesHwmon for each folder
// updatesHwmon for each folder
hwmonPathName := path. Join ( sysFilePath ( "class" ) , "hwmon" )
hwmonPathName := file path. Join ( sysFilePath ( "class" ) , "hwmon" )
hwmonFiles , err := ioutil . ReadDir ( hwmonPathName )
hwmonFiles , err := ioutil . ReadDir ( hwmonPathName )
if err != nil {
if err != nil {
@ -431,7 +430,7 @@ func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) error {
}
}
for _ , hwDir := range hwmonFiles {
for _ , hwDir := range hwmonFiles {
hwmonXPathName := path. Join ( hwmonPathName , hwDir . Name ( ) )
hwmonXPathName := file path. Join ( hwmonPathName , hwDir . Name ( ) )
if hwDir . Mode ( ) & os . ModeSymlink > 0 {
if hwDir . Mode ( ) & os . ModeSymlink > 0 {
hwDir , err = os . Stat ( hwmonXPathName )
hwDir , err = os . Stat ( hwmonXPathName )