Browse Source

vendor https://github.com/mdlayher/lmsensors (#18427)

Ilya Mashchenko 6 months ago
parent
commit
01ce883ea6

+ 34 - 172
REDISTRIBUTED.md

@@ -23,176 +23,38 @@ We have decided to redistribute all these, instead of using them
 through a CDN, to allow Netdata to work in cases where Internet
 connectivity is not available.
 
--   [Dygraphs](http://dygraphs.com/)
-
-      Copyright 2009, Dan Vanderkam
-      [MIT License](http://dygraphs.com/legal.html)
-
--   [Easy Pie Chart](https://rendro.github.io/easy-pie-chart/)
-
-      Copyright 2013, Robert Fleischmann
-      [MIT License](https://github.com/rendro/easy-pie-chart/blob/master/LICENSE)
-
--   [Gauge.js](http://bernii.github.io/gauge.js/)
-
-      Copyright, Bernard Kobos
-      [MIT License](https://github.com/getgauge/gauge-js/blob/master/LICENSE)
-
--   [d3pie](https://github.com/benkeen/d3pie)
-
-      Copyright (c) 2014-2015 Benjamin Keen
-      [MIT License](https://github.com/benkeen/d3pie/blob/master/LICENSE)
-
--   [jQuery Sparklines](http://omnipotent.net/jquery.sparkline/)
-
-      Copyright 2009-2012, Splunk Inc.
-      [New BSD License](http://opensource.org/licenses/BSD-3-Clause)
-
--   [Peity](http://benpickles.github.io/peity/)
-
-      Copyright 2009-2015, Ben Pickles
-      [MIT License](https://github.com/benpickles/peity/blob/master/LICENCE)
-
--   [morris.js](http://morrisjs.github.io/morris.js/)
-
-      Copyright 2013, Olly Smith
-      [Simplified BSD License](http://morrisjs.github.io/morris.js/)
-
--   [Raphaël](http://dmitrybaranovskiy.github.io/raphael/)
-
-      Copyright 2008, Dmitry Baranovskiy
-      [MIT License](http://dmitrybaranovskiy.github.io/raphael/license.html)
-
--   [C3](http://c3js.org/)
-
-      Copyright 2013, Masayuki Tanaka
-      [MIT License](https://github.com/masayuki0812/c3/blob/master/LICENSE)
-
--   [D3](http://d3js.org/)
-
-      Copyright 2015, Mike Bostock
-      [BSD License](http://opensource.org/licenses/BSD-3-Clause)
-
--   [jQuery](https://jquery.org/)
-
-      Copyright 2015, jQuery Foundation
-      [MIT License](https://jquery.org/license/)
-
--   [Bootstrap](http://getbootstrap.com/getting-started/)
-
-      Copyright 2015, Twitter
-      [MIT License](https://github.com/twbs/bootstrap/blob/v4-dev/LICENSE)
-
--   [Bootstrap Toggle](http://www.bootstraptoggle.com/)
-
-      Copyright (c) 2011-2014 Min Hur, The New York Times Company
-      [MIT License](https://github.com/minhur/bootstrap-toggle/blob/master/LICENSE)
-
--   [Bootstrap-slider](http://seiyria.com/bootstrap-slider/)
-
-      Copyright 2017 Kyle Kemp, Rohit Kalkur, and contributors
-      [MIT License](https://github.com/seiyria/bootstrap-slider/blob/master/LICENSE.md)
-
--   [bootstrap-table](http://bootstrap-table.wenzhixin.net.cn/)
-
-      Copyright (c) 2012-2016 Zhixin Wen [wenzhixin2010@gmail.com](mailto:wenzhixin2010@gmail.com)
-      [MIT License](https://github.com/wenzhixin/bootstrap-table/blob/master/LICENSE)
-
--   [tableExport.jquery.plugin](https://github.com/hhurz/tableExport.jquery.plugin)
-
-      Copyright (c) 2015,2016 hhurz
-      [MIT License](https://github.com/hhurz/tableExport.jquery.plugin/blob/master/LICENSE)
-
--   [perfect-scrollbar](https://jamesflorentino.github.io/nanoScrollerJS/)
-
-      Copyright 2016, Hyunje Alex Jun and other contributors
-      [MIT License](https://github.com/noraesae/perfect-scrollbar/blob/master/LICENSE)
-
--   [FontAwesome](https://github.com/FortAwesome/Font-Awesome)
-
-      Created by Dave Gandy
-      Font license: [SIL OFL 1.1](http://scripts.sil.org/OFL)
-      Icon license [Creative Commons Attribution 4.0 (CC-BY 4.0)](https://creativecommons.org/licenses/by/4.0/)
-      Code license: [MIT License](http://opensource.org/licenses/mit-license.html)
-
--   [node-extend](https://github.com/justmoon/node-extend)
-
-      Copyright 2014, Stefan Thomas
-      [MIT License](https://github.com/justmoon/node-extend/blob/master/LICENSE)
-
--   [node-net-snmp](https://github.com/stephenwvickers/node-net-snmp)
-
-      Copyright 2013, Stephen Vickers
-      [MIT License](https://github.com/nospaceships/node-net-snmp#license)
-
--   [node-asn1-ber](https://github.com/stephenwvickers/node-asn1-ber)
-
-      Copyright 2017, Stephen Vickers
-      Copyright 2011, Mark Cavage
-      [MIT License](https://github.com/nospaceships/node-asn1-ber#license)
-
--   [pixl-xml](https://github.com/jhuckaby/pixl-xml)
-
-      Copyright 2015, Joseph Huckaby
-      [MIT License](https://github.com/jhuckaby/pixl-xml#license)
-
--   [sensors](https://github.com/paroj/sensors.py)
-
-      Copyright 2014, Pavel Rojtberg
-      [LGPL 2.1 License](http://opensource.org/licenses/LGPL-2.1)
-
--   [PyYAML](https://pypi.org/project/PyYAML/)
-
-      Copyright 2006, Kirill Simonov
-      [MIT License](https://github.com/yaml/pyyaml/blob/master/LICENSE)
-
--   [urllib3](https://github.com/shazow/urllib3)
-
-      Copyright 2008-2016 Andrey Petrov and [contributors](https://github.com/shazow/urllib3/blob/master/CONTRIBUTORS.txt)
-      [MIT License](https://github.com/shazow/urllib3/blob/master/LICENSE.txt)
-
--   [lz-string](http://pieroxy.net/blog/pages/lz-string/index.html)
-
-      Copyright 2013 Pieroxy
-      [WTFPL License](http://pieroxy.net/blog/pages/lz-string/index.html#inline_menu_10)
-
--   [pako](http://nodeca.github.io/pako/)
-
-      Copyright 2014-2017 Vitaly Puzrin and Andrei Tuputcyn
-      [MIT License](https://github.com/nodeca/pako/blob/master/LICENSE)
-
--   [clipboard-polyfill](https://github.com/lgarron/clipboard-polyfill)
-
-      Copyright (c) 2014 Lucas Garron
-      [MIT License](https://github.com/lgarron/clipboard-polyfill/blob/master/LICENSE.md)
-
--   [Utilities for writing code that runs on Python 2 and 3](https://raw.githubusercontent.com/netdata/netdata/master/src/collectors/python.d.plugin/python_modules/urllib3/packages/six.py)
-
-      Copyright (c) 2010-2015 Benjamin Peterson
-      [MIT License](https://github.com/benjaminp/six/blob/master/LICENSE)
-
--   [mcrcon](https://github.com/barneygale/MCRcon)
-
-      Copyright (C) 2015 Barnaby Gale
-      [MIT License](https://raw.githubusercontent.com/barneygale/MCRcon/master/COPYING.txt)
-
--   [monotonic](https://github.com/atdt/monotonic)
-
-      Copyright 2014, 2015, 2016 Ori Livneh [ori@wikimedia.org](mailto:ori@wikimedia.org)
-      [Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0)
-
--   [filelock](https://github.com/benediktschmitt/py-filelock)
-
-    Copyright 2015, Benedikt Schmitt [Unlicense License](https://unlicense.org/)
-
--   [Kolmogorov-Smirnov distribution](http://simul.iro.umontreal.ca/ksdir/)
-
-    Copyright March 2010 by Université de Montréal, Richard Simard and Pierre L'Ecuyer
-    [GPL 3.0](https://www.gnu.org/licenses/gpl-3.0.en.html)
-
--   [xxHash](https://github.com/Cyan4973/xxHash)
-
-    Copyright (c) 2012-2021 Yann Collet
-    [BSD](https://github.com/Cyan4973/xxHash/blob/dev/LICENSE)
-
 
+| Name                                                                                                                                                                                     | Copyright                                                                          | License                                                                                                                                                                                                           |
+|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| [Dygraphs](http://dygraphs.com/)                                                                                                                                                         | Copyright 2009, Dan Vanderkam                                                      | [MIT](http://dygraphs.com/legal.html)                                                                                                                                                                             |
+| [Easy Pie Chart](https://rendro.github.io/easy-pie-chart/)                                                                                                                               | Copyright 2013, Robert Fleischmann                                                 | [MIT](https://github.com/rendro/easy-pie-chart/blob/master/LICENSE)                                                                                                                                               |
+| [Gauge.js](http://bernii.github.io/gauge.js/)                                                                                                                                            | Copyright, Bernard Kobos                                                           | [MIT](https://github.com/getgauge/gauge-js/blob/master/LICENSE)                                                                                                                                                   |
+| [d3pie](https://github.com/benkeen/d3pie)                                                                                                                                                | Copyright (c) 2014-2015 Benjamin Keen                                              | [MIT](https://github.com/benkeen/d3pie/blob/master/LICENSE)                                                                                                                                                       |
+| [jQuery Sparklines](http://omnipotent.net/jquery.sparkline/)                                                                                                                             | Copyright 2009-2012, Splunk Inc.                                                   | [New BSD](http://opensource.org/licenses/BSD-3-Clause)                                                                                                                                                            |
+| [Peity](http://benpickles.github.io/peity/)                                                                                                                                              | Copyright 2009-2015, Ben Pickles                                                   | [MIT](https://github.com/benpickles/peity/blob/master/LICENCE)                                                                                                                                                    |
+| [morris.js](http://morrisjs.github.io/morris.js/)                                                                                                                                        | Copyright 2013, Olly Smith                                                         | [Simplified BSD](http://morrisjs.github.io/morris.js/)                                                                                                                                                            |
+| [Raphaël](http://dmitrybaranovskiy.github.io/raphael/)                                                                                                                                   | Copyright 2008, Dmitry Baranovskiy                                                 | [MIT](http://dmitrybaranovskiy.github.io/raphael/license.html)                                                                                                                                                    |
+| [C3](http://c3js.org/)                                                                                                                                                                   | Copyright 2013, Masayuki Tanaka                                                    | [MIT](https://github.com/masayuki0812/c3/blob/master/LICENSE)                                                                                                                                                     |
+| [D3](http://d3js.org/)                                                                                                                                                                   | Copyright 2015, Mike Bostock                                                       | [BSD](http://opensource.org/licenses/BSD-3-Clause)                                                                                                                                                                |
+| [jQuery](https://jquery.org/)                                                                                                                                                            | Copyright 2015, jQuery Foundation                                                  | [MIT](https://jquery.org/license/)                                                                                                                                                                                |
+| [Bootstrap](http://getbootstrap.com/getting-started/)                                                                                                                                    | Copyright 2015, Twitter                                                            | [MIT](https://github.com/twbs/bootstrap/blob/v4-dev/LICENSE)                                                                                                                                                      |
+| [Bootstrap Toggle](http://www.bootstraptoggle.com/)                                                                                                                                      | Copyright (c) 2011-2014 Min Hur, The New York Times Company                        | [MIT](https://github.com/minhur/bootstrap-toggle/blob/master/LICENSE)                                                                                                                                             |
+| [Bootstrap-slider](http://seiyria.com/bootstrap-slider/)                                                                                                                                 | Copyright 2017 Kyle Kemp, Rohit Kalkur, and contributors                           | [MIT](https://github.com/seiyria/bootstrap-slider/blob/master/LICENSE.md)                                                                                                                                         |
+| [bootstrap-table](http://bootstrap-table.wenzhixin.net.cn/)                                                                                                                              | Copyright (c) 2012-2016 Zhixin Wen                                                 | [MIT](https://github.com/wenzhixin/bootstrap-table/blob/master/LICENSE)                                                                                                                                           |
+| [tableExport.jquery.plugin](https://github.com/hhurz/tableExport.jquery.plugin)                                                                                                          | Copyright (c) 2015,2016 hhurz                                                      | [MIT](https://github.com/hhurz/tableExport.jquery.plugin/blob/master/LICENSE)                                                                                                                                     |
+| [perfect-scrollbar](https://jamesflorentino.github.io/nanoScrollerJS/)                                                                                                                   | Copyright 2016, Hyunje Alex Jun and other contributors                             | [MIT](https://github.com/noraesae/perfect-scrollbar/blob/master/LICENSE)                                                                                                                                          |
+| [FontAwesome](https://github.com/FortAwesome/Font-Awesome)                                                                                                                               | Created by Dave Gandy                                                              | Font: [SIL OFL 1.1](http://scripts.sil.org/OFL), Icon: [Creative Commons Attribution 4.0 (CC-BY 4.0)](https://creativecommons.org/licenses/by/4.0/), Code: [MIT](http://opensource.org/licenses/mit-license.html) |
+| [node-extend](https://github.com/justmoon/node-extend)                                                                                                                                   | Copyright 2014, Stefan Thomas                                                      | [MIT](https://github.com/justmoon/node-extend/blob/master/LICENSE)                                                                                                                                                |
+| [pixl-xml](https://github.com/jhuckaby/pixl-xml)                                                                                                                                         | Copyright 2015, Joseph Huckaby                                                     | [MIT](https://github.com/jhuckaby/pixl-xml#license)                                                                                                                                                               |
+| [PyYAML](https://pypi.org/project/PyYAML/)                                                                                                                                               | Copyright 2006, Kirill Simonov                                                     | [MIT](https://github.com/yaml/pyyaml/blob/master/LICENSE)                                                                                                                                                         |
+| [urllib3](https://github.com/shazow/urllib3)                                                                                                                                             | Copyright 2008-2016 Andrey Petrov and contributors                                 | [MIT](https://github.com/shazow/urllib3/blob/master/LICENSE.txt)                                                                                                                                                  |
+| [lz-string](http://pieroxy.net/blog/pages/lz-string/index.html)                                                                                                                          | Copyright 2013 Pieroxy                                                             | [WTFPL](http://pieroxy.net/blog/pages/lz-string/index.html#inline_menu_10)                                                                                                                                        |
+| [pako](http://nodeca.github.io/pako/)                                                                                                                                                    | Copyright 2014-2017 Vitaly Puzrin and Andrei Tuputcyn                              | [MIT](https://github.com/nodeca/pako/blob/master/LICENSE)                                                                                                                                                         |
+| [clipboard-polyfill](https://github.com/lgarron/clipboard-polyfill)                                                                                                                      | Copyright (c) 2014 Lucas Garron                                                    | [MIT](https://github.com/lgarron/clipboard-polyfill/blob/master/LICENSE.md)                                                                                                                                       |
+| [Utilities for writing code that runs on Python 2 and 3](https://raw.githubusercontent.com/netdata/netdata/master/src/collectors/python.d.plugin/python_modules/urllib3/packages/six.py) | Copyright (c) 2010-2015 Benjamin Peterson                                          | [MIT](https://github.com/benjaminp/six/blob/master/LICENSE)                                                                                                                                                       |
+| [mcrcon](https://github.com/barneygale/MCRcon)                                                                                                                                           | Copyright (C) 2015 Barnaby Gale                                                    | [MIT](https://raw.githubusercontent.com/barneygale/MCRcon/master/COPYING.txt)                                                                                                                                     |
+| [monotonic](https://github.com/atdt/monotonic)                                                                                                                                           | Copyright 2014, 2015, 2016 Ori Livneh                                              | [Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0)                                                                                                                                                          |
+| [filelock](https://github.com/benediktschmitt/py-filelock)                                                                                                                               | Copyright 2015, Benedikt Schmitt                                                   | [Unlicense](https://unlicense.org/)                                                                                                                                                                               |
+| [Kolmogorov-Smirnov distribution](http://simul.iro.umontreal.ca/ksdir/)                                                                                                                  | Copyright March 2010 by Université de Montréal, Richard Simard and Pierre L'Ecuyer | [GPL 3.0](https://www.gnu.org/licenses/gpl-3.0.en.html)                                                                                                                                                           |
+| [xxHash](https://github.com/Cyan4973/xxHash)                                                                                                                                             | Copyright (c) 2012-2021 Yann Collet                                                | [BSD](https://github.com/Cyan4973/xxHash/blob/dev/LICENSE)                                                                                                                                                        |
+| [lmsensors](https://github.com/mdlayher/lmsensors)                                                                                                                                       | Copyright 2016, Matt Layher                                                        | [MIT](https://github.com/mdlayher/lmsensors/blob/master/LICENSE.md)                                                                                                                                               |

+ 10 - 0
src/go/plugin/go.d/modules/sensors/lmsensors/LICENSE.md

@@ -0,0 +1,10 @@
+MIT License
+===========
+
+Copyright (C) 2016 Matt Layher
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 5 - 0
src/go/plugin/go.d/modules/sensors/lmsensors/README.md

@@ -0,0 +1,5 @@
+lmsensors [![Build Status](https://travis-ci.org/mdlayher/lmsensors.svg?branch=master)](https://travis-ci.org/mdlayher/lmsensors) [![GoDoc](http://godoc.org/github.com/mdlayher/lmsensors?status.svg)](http://godoc.org/github.com/mdlayher/lmsensors) [![Report Card](https://goreportcard.com/badge/github.com/mdlayher/lmsensors)](https://goreportcard.com/report/github.com/mdlayher/lmsensors)
+=========
+
+Package `lmsensors` provides access to Linux monitoring sensors data, such
+as temperatures, voltage, and fan speeds.  MIT Licensed.

+ 62 - 0
src/go/plugin/go.d/modules/sensors/lmsensors/currentsensor.go

@@ -0,0 +1,62 @@
+package lmsensors
+
+import (
+	"strconv"
+)
+
+var _ Sensor = &CurrentSensor{}
+
+// A CurrentSensor is a Sensor that detects current in Amperes.
+type CurrentSensor struct {
+	// The name of the sensor.
+	Name string
+
+	// A label that describes what the sensor is monitoring.  Label may be
+	// empty.
+	Label string
+
+	// Whether or not the sensor has an alarm triggered.
+	Alarm bool
+
+	// The input current, in Amperes, indicated by the sensor.
+	Input float64
+
+	// The maximum current threshold, in Amperes, indicated by the sensor.
+	Maximum float64
+
+	// The critical current threshold, in Amperes, indicated by the sensor.
+	Critical float64
+}
+
+func (s *CurrentSensor) name() string        { return s.Name }
+func (s *CurrentSensor) setName(name string) { s.Name = name }
+
+func (s *CurrentSensor) parse(raw map[string]string) error {
+	for k, v := range raw {
+		switch k {
+		case "crit", "input", "max":
+			f, err := strconv.ParseFloat(v, 64)
+			if err != nil {
+				return err
+			}
+
+			// Raw current values are scaled by 1000
+			f /= 1000
+
+			switch k {
+			case "crit":
+				s.Critical = f
+			case "input":
+				s.Input = f
+			case "max":
+				s.Maximum = f
+			}
+		case "alarm":
+			s.Alarm = v != "0"
+		case "label":
+			s.Label = v
+		}
+	}
+
+	return nil
+}

+ 3 - 0
src/go/plugin/go.d/modules/sensors/lmsensors/doc.go

@@ -0,0 +1,3 @@
+// Package lmsensors provides access to Linux monitoring sensors data, such
+// as temperatures, voltage, and fan speeds.
+package lmsensors

+ 55 - 0
src/go/plugin/go.d/modules/sensors/lmsensors/fansensor.go

@@ -0,0 +1,55 @@
+package lmsensors
+
+import (
+	"strconv"
+)
+
+var _ Sensor = &FanSensor{}
+
+// A FanSensor is a Sensor that detects fan speeds in rotations per minute.
+type FanSensor struct {
+	// The name of the sensor.
+	Name string
+
+	// Whether or not the fan speed is below the minimum threshold.
+	Alarm bool
+
+	// Whether or not the fan will sound an audible alarm when fan speed is
+	// below the minimum threshold.
+	Beep bool
+
+	// The input fan speed, in rotations per minute, indicated by the sensor.
+	Input int
+
+	// The low threshold fan speed, in rotations per minute, indicated by the
+	// sensor.
+	Minimum int
+}
+
+func (s *FanSensor) name() string        { return s.Name }
+func (s *FanSensor) setName(name string) { s.Name = name }
+
+func (s *FanSensor) parse(raw map[string]string) error {
+	for k, v := range raw {
+		switch k {
+		case "input", "min":
+			i, err := strconv.Atoi(v)
+			if err != nil {
+				return err
+			}
+
+			switch k {
+			case "input":
+				s.Input = i
+			case "min":
+				s.Minimum = i
+			}
+		case "alarm":
+			s.Alarm = v != "0"
+		case "beep":
+			s.Beep = v != "0"
+		}
+	}
+
+	return nil
+}

+ 28 - 0
src/go/plugin/go.d/modules/sensors/lmsensors/intrusionsensor.go

@@ -0,0 +1,28 @@
+package lmsensors
+
+var _ Sensor = &IntrusionSensor{}
+
+// An IntrusionSensor is a Sensor that detects when the machine's chassis
+// has been opened.
+type IntrusionSensor struct {
+	// The name of the sensor.
+	Name string
+
+	// Whether or not the machine's chassis has been opened, and the alarm
+	// has been triggered.
+	Alarm bool
+}
+
+func (s *IntrusionSensor) name() string        { return s.Name }
+func (s *IntrusionSensor) setName(name string) { s.Name = name }
+
+func (s *IntrusionSensor) parse(raw map[string]string) error {
+	for k, v := range raw {
+		switch k {
+		case "alarm":
+			s.Alarm = v != "0"
+		}
+	}
+
+	return nil
+}

+ 72 - 0
src/go/plugin/go.d/modules/sensors/lmsensors/powersensor.go

@@ -0,0 +1,72 @@
+package lmsensors
+
+import (
+	"strconv"
+	"time"
+)
+
+var _ Sensor = &PowerSensor{}
+
+// A PowerSensor is a Sensor that detects average electrical power consumption
+// in watts.
+type PowerSensor struct {
+	// The name of the sensor.
+	Name string
+
+	// The average electrical power consumption, in watts, indicated
+	// by the sensor.
+	Average float64
+
+	// The interval of time over which the average electrical power consumption
+	// is collected.
+	AverageInterval time.Duration
+
+	// Whether or not this sensor has a battery.
+	Battery bool
+
+	// The model number of the sensor.
+	ModelNumber string
+
+	// Miscellaneous OEM information about the sensor.
+	OEMInfo string
+
+	// The serial number of the sensor.
+	SerialNumber string
+}
+
+func (s *PowerSensor) name() string        { return s.Name }
+func (s *PowerSensor) setName(name string) { s.Name = name }
+
+func (s *PowerSensor) parse(raw map[string]string) error {
+	for k, v := range raw {
+		switch k {
+		case "average":
+			f, err := strconv.ParseFloat(v, 64)
+			if err != nil {
+				return err
+			}
+
+			// Raw temperature values are scaled by one million
+			f /= 1000000
+			s.Average = f
+		case "average_interval":
+			// Time values in milliseconds
+			d, err := time.ParseDuration(v + "ms")
+			if err != nil {
+				return err
+			}
+
+			s.AverageInterval = d
+		case "is_battery":
+			s.Battery = v != "0"
+		case "model_number":
+			s.ModelNumber = v
+		case "oem_info":
+			s.OEMInfo = v
+		case "serial_number":
+			s.SerialNumber = v
+		}
+	}
+
+	return nil
+}

+ 232 - 0
src/go/plugin/go.d/modules/sensors/lmsensors/scanner.go

@@ -0,0 +1,232 @@
+package lmsensors
+
+import (
+	"fmt"
+	"io/ioutil"
+	"os"
+	"path/filepath"
+	"strings"
+)
+
+// A filesystem is an interface to a filesystem, used for testing.
+type filesystem interface {
+	ReadFile(filename string) (string, error)
+	Readlink(name string) (string, error)
+	Stat(name string) (os.FileInfo, error)
+	Walk(root string, walkFn filepath.WalkFunc) error
+}
+
+// A Scanner scans for Devices, so data can be read from their Sensors.
+type Scanner struct {
+	fs filesystem
+}
+
+// New creates a new Scanner.
+func New() *Scanner {
+	return &Scanner{
+		fs: &systemFilesystem{},
+	}
+}
+
+// Scan scans for Devices and their Sensors.
+func (s *Scanner) Scan() ([]*Device, error) {
+	// Determine common device locations in Linux /sys filesystem.
+	paths, err := s.detectDevicePaths()
+	if err != nil {
+		return nil, err
+	}
+
+	var devices []*Device
+	for _, p := range paths {
+		d := &Device{}
+		raw := make(map[string]map[string]string, 0)
+
+		// Walk filesystem paths to fetch devices and sensors
+		err := s.fs.Walk(p, func(path string, info os.FileInfo, err error) error {
+			if err != nil {
+				return err
+			}
+
+			// Skip directories and anything that isn't a regular file
+			if info.IsDir() || !info.Mode().IsRegular() {
+				return nil
+			}
+
+			// Skip some files that can't be read or don't provide useful
+			// sensor information
+			file := filepath.Base(path)
+			if shouldSkip(file) {
+				return nil
+			}
+
+			s, err := s.fs.ReadFile(path)
+			if err != nil {
+				return nil
+			}
+
+			switch file {
+			// Found name of device
+			case "name":
+				d.Name = s
+			}
+
+			// Sensor names in format "sensor#_foo", e.g. "temp1_input"
+			fs := strings.SplitN(file, "_", 2)
+			if len(fs) != 2 {
+				return nil
+			}
+
+			// Gather sensor data into map for later processing
+			if _, ok := raw[fs[0]]; !ok {
+				raw[fs[0]] = make(map[string]string, 0)
+			}
+
+			raw[fs[0]][fs[1]] = s
+			return nil
+		})
+		if err != nil {
+			return nil, err
+		}
+
+		// Parse all possible sensors from raw data
+		sensors, err := parseSensors(raw)
+		if err != nil {
+			return nil, err
+		}
+
+		d.Sensors = sensors
+		devices = append(devices, d)
+	}
+
+	renameDevices(devices)
+	return devices, nil
+}
+
+// renameDevices renames devices in place to prevent duplicate device names,
+// and to number each device.
+func renameDevices(devices []*Device) {
+	nameCount := make(map[string]int, 0)
+
+	for i := range devices {
+		name := devices[i].Name
+		devices[i].Name = fmt.Sprintf("%s-%02d",
+			name,
+			nameCount[name],
+		)
+		nameCount[name]++
+	}
+}
+
+// detectDevicePaths performs a filesystem walk to paths where devices may
+// reside on Linux.
+func (s *Scanner) detectDevicePaths() ([]string, error) {
+	const lookPath = "/sys/class/hwmon"
+
+	var paths []string
+	err := s.fs.Walk(lookPath, func(path string, info os.FileInfo, err error) error {
+		if err != nil {
+			return err
+		}
+
+		// Skip anything that isn't a symlink
+		if info.Mode()&os.ModeSymlink == 0 {
+			return nil
+		}
+
+		dest, err := s.fs.Readlink(path)
+		if err != nil {
+			return err
+		}
+		dest = filepath.Join(lookPath, filepath.Clean(dest))
+
+		// Symlink destination has a file called name, meaning a sensor exists
+		// here and data can be retrieved
+		fi, err := s.fs.Stat(filepath.Join(dest, "name"))
+		if err != nil && !os.IsNotExist(err) {
+			return err
+		}
+		if err == nil && fi.Mode().IsRegular() {
+			paths = append(paths, dest)
+			return nil
+		}
+
+		// Symlink destination has another symlink called device, which can be
+		// read and used to retrieve data
+		device := filepath.Join(dest, "device")
+		fi, err = s.fs.Stat(device)
+		if err != nil {
+			if os.IsNotExist(err) {
+				return nil
+			}
+
+			return err
+		}
+
+		if fi.Mode()&os.ModeSymlink != 0 {
+			return nil
+		}
+
+		device, err = s.fs.Readlink(device)
+		if err != nil {
+			return err
+		}
+		dest = filepath.Join(dest, filepath.Clean(device))
+
+		// Symlink destination has a file called name, meaning a sensor exists
+		// here and data can be retrieved
+		if _, err := s.fs.Stat(filepath.Join(dest, "name")); err != nil {
+			if os.IsNotExist(err) {
+				return nil
+			}
+
+			return err
+		}
+
+		paths = append(paths, dest)
+		return nil
+	})
+
+	return paths, err
+}
+
+// shouldSkip indicates if a given filename should be skipped during the
+// filesystem walk operation.
+func shouldSkip(file string) bool {
+	if strings.HasPrefix(file, "runtime_") {
+		return true
+	}
+
+	switch file {
+	case "async":
+	case "autosuspend_delay_ms":
+	case "control":
+	case "driver_override":
+	case "modalias":
+	case "uevent":
+	default:
+		return false
+	}
+
+	return true
+}
+
+var _ filesystem = &systemFilesystem{}
+
+// A systemFilesystem is a filesystem which uses operations on the host
+// filesystem.
+type systemFilesystem struct{}
+
+func (fs *systemFilesystem) ReadFile(filename string) (string, error) {
+	b, err := ioutil.ReadFile(filename)
+	if err != nil {
+		return "", err
+	}
+
+	return strings.TrimSpace(string(b)), nil
+}
+
+func (fs *systemFilesystem) Readlink(name string) (string, error)  { return os.Readlink(name) }
+func (fs *systemFilesystem) Stat(name string) (os.FileInfo, error) { return os.Stat(name) }
+func (fs *systemFilesystem) Walk(root string, walkFn filepath.WalkFunc) error {
+	return filepath.Walk(root, walkFn)
+}

+ 810 - 0
src/go/plugin/go.d/modules/sensors/lmsensors/scanner_test.go

@@ -0,0 +1,810 @@
+package lmsensors
+
+import (
+	"fmt"
+	"os"
+	"path/filepath"
+	"reflect"
+	"strings"
+	"testing"
+	"time"
+)
+
+// TODO(mdlayher): why does scanning work if device file isn't a symlink,
+// even though it is in the actual filesystem (and the actual filesystem
+// exhibits the same behavior)?
+
+func TestScannerScan(t *testing.T) {
+	tests := []struct {
+		name    string
+		fs      filesystem
+		devices []*Device
+	}{
+		{
+			name: "power_meter device",
+			fs: &memoryFilesystem{
+				symlinks: map[string]string{
+					"/sys/class/hwmon/hwmon0": "../../devices/LNXSYSTM:00/device:00/ACPI0000:00/hwmon/hwmon0",
+					"/sys/devices/LNXSYSTM:00/device:00/ACPI0000:00/hwmon/hwmon0/device": "../../../ACPI0000:00",
+				},
+				files: []memoryFile{
+					{
+						name: "/sys/class/hwmon",
+						info: &memoryFileInfo{
+							isDir: true,
+						},
+					},
+					{
+						name: "/sys/class/hwmon/hwmon0",
+						info: &memoryFileInfo{
+							mode: os.ModeSymlink,
+						},
+					},
+					{
+						name: "/sys/devices/LNXSYSTM:00/device:00/ACPI0000:00",
+						info: &memoryFileInfo{
+							isDir: true,
+						},
+					},
+					{
+						name: "/sys/devices/LNXSYSTM:00/device:00/ACPI0000:00/hwmon/hwmon0/name",
+						err:  os.ErrNotExist,
+					},
+					{
+						name: "/sys/devices/LNXSYSTM:00/device:00/ACPI0000:00/hwmon/hwmon0/device",
+						info: &memoryFileInfo{
+							// mode: os.ModeSymlink,
+						},
+					},
+					{
+						name:     "/sys/devices/LNXSYSTM:00/device:00/ACPI0000:00/name",
+						contents: "power_meter",
+					},
+					{
+						name:     "/sys/devices/LNXSYSTM:00/device:00/ACPI0000:00/power1_average",
+						contents: "345000000",
+					},
+					{
+						name:     "/sys/devices/LNXSYSTM:00/device:00/ACPI0000:00/power1_average_interval",
+						contents: "1000",
+					},
+					{
+						name:     "/sys/devices/LNXSYSTM:00/device:00/ACPI0000:00/power1_is_battery",
+						contents: "0",
+					},
+					{
+						name:     "/sys/devices/LNXSYSTM:00/device:00/ACPI0000:00/power1_model_number",
+						contents: "Intel(R) Node Manager",
+					},
+					{
+						name:     "/sys/devices/LNXSYSTM:00/device:00/ACPI0000:00/power1_oem_info",
+						contents: "Meter measures total domain",
+					},
+					{
+						name:     "/sys/devices/LNXSYSTM:00/device:00/ACPI0000:00/power1_serial_number",
+						contents: "",
+					},
+				},
+			},
+			devices: []*Device{{
+				Name: "power_meter-00",
+				Sensors: []Sensor{
+					&PowerSensor{
+						Name:            "power1",
+						Average:         345.0,
+						AverageInterval: 1 * time.Second,
+						Battery:         false,
+						ModelNumber:     "Intel(R) Node Manager",
+						OEMInfo:         "Meter measures total domain",
+						SerialNumber:    "",
+					},
+				},
+			}},
+		},
+		{
+			name: "acpitz device",
+			fs: &memoryFilesystem{
+				symlinks: map[string]string{
+					"/sys/class/hwmon/hwmon0": "../../devices/virtual/hwmon/hwmon0",
+				},
+				files: []memoryFile{
+					{
+						name: "/sys/class/hwmon",
+						info: &memoryFileInfo{
+							isDir: true,
+						},
+					},
+					{
+						name: "/sys/class/hwmon/hwmon0",
+						info: &memoryFileInfo{
+							mode: os.ModeSymlink,
+						},
+					},
+					{
+						name: "/sys/devices/virtual/hwmon/hwmon0",
+						info: &memoryFileInfo{
+							isDir: true,
+						},
+					},
+					{
+						name:     "/sys/devices/virtual/hwmon/hwmon0/name",
+						contents: "acpitz",
+					},
+					{
+						name:     "/sys/devices/virtual/hwmon/hwmon0/temp1_crit",
+						contents: "105000",
+					},
+					{
+						name:     "/sys/devices/virtual/hwmon/hwmon0/temp1_input",
+						contents: "27800",
+					},
+				},
+			},
+			devices: []*Device{{
+				Name: "acpitz-00",
+				Sensors: []Sensor{
+					&TemperatureSensor{
+						Name:          "temp1",
+						Input:         27.8,
+						Critical:      105.0,
+						CriticalAlarm: false,
+					},
+				},
+			}},
+		},
+		{
+			name: "coretemp device",
+			fs: &memoryFilesystem{
+				symlinks: map[string]string{
+					"/sys/class/hwmon/hwmon1":                              "../../devices/platform/coretemp.0/hwmon/hwmon1",
+					"/sys/devices/platform/coretemp.0/hwmon/hwmon1/device": "../../../coretemp.0",
+				},
+				files: []memoryFile{
+					{
+						name: "/sys/class/hwmon",
+						info: &memoryFileInfo{
+							isDir: true,
+						},
+					},
+					{
+						name: "/sys/class/hwmon/hwmon1",
+						info: &memoryFileInfo{
+							mode: os.ModeSymlink,
+						},
+					},
+					{
+						name: "/sys/devices/platform/coretemp.0",
+						info: &memoryFileInfo{
+							isDir: true,
+						},
+					},
+					{
+						name: "/sys/devices/platform/coretemp.0/hwmon/hwmon1/name",
+						err:  os.ErrNotExist,
+					},
+					{
+						name: "/sys/devices/platform/coretemp.0/hwmon/hwmon1/device",
+						info: &memoryFileInfo{
+							// mode: os.ModeSymlink,
+						},
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/name",
+						contents: "coretemp",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp1_crit",
+						contents: "100000",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp1_crit_alarm",
+						contents: "0",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp1_input",
+						contents: "40000",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp1_label",
+						contents: "Core 0",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp1_max",
+						contents: "80000",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp2_crit",
+						contents: "100000",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp2_crit_alarm",
+						contents: "0",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp2_input",
+						contents: "42000",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp2_label",
+						contents: "Core 1",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp2_max",
+						contents: "80000",
+					},
+				},
+			},
+			devices: []*Device{{
+				Name: "coretemp-00",
+				Sensors: []Sensor{
+					&TemperatureSensor{
+						Name:          "temp1",
+						Label:         "Core 0",
+						Input:         40.0,
+						High:          80.0,
+						Critical:      100.0,
+						CriticalAlarm: false,
+					},
+					&TemperatureSensor{
+						Name:          "temp2",
+						Label:         "Core 1",
+						Input:         42.0,
+						High:          80.0,
+						Critical:      100.0,
+						CriticalAlarm: false,
+					},
+				},
+			}},
+		},
+		{
+			name: "it8728 device",
+			fs: &memoryFilesystem{
+				symlinks: map[string]string{
+					"/sys/class/hwmon/hwmon2":                             "../../devices/platform/it87.2608/hwmon/hwmon2",
+					"/sys/devices/platform/it87.2608/hwmon/hwmon2/device": "../../../it87.2608",
+				},
+				files: []memoryFile{
+					{
+						name: "/sys/class/hwmon",
+						info: &memoryFileInfo{
+							isDir: true,
+						},
+					},
+					{
+						name: "/sys/class/hwmon/hwmon2",
+						info: &memoryFileInfo{
+							mode: os.ModeSymlink,
+						},
+					},
+					{
+						name: "/sys/devices/platform/it87.2608",
+						info: &memoryFileInfo{
+							isDir: true,
+						},
+					},
+					{
+						name: "/sys/devices/platform/it87.2608/hwmon/hwmon2/name",
+						err:  os.ErrNotExist,
+					},
+					{
+						name: "/sys/devices/platform/it87.2608/hwmon/hwmon2/device",
+						info: &memoryFileInfo{
+							// mode: os.ModeSymlink,
+						},
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/name",
+						contents: "it8728",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/fan1_alarm",
+						contents: "0",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/fan1_beep",
+						contents: "1",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/fan1_input",
+						contents: "1010",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/fan1_min",
+						contents: "10",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/in0_alarm",
+						contents: "0",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/in0_beep",
+						contents: "0",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/in0_input",
+						contents: "1056",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/in0_max",
+						contents: "3060",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/in1_alarm",
+						contents: "0",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/in1_beep",
+						contents: "0",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/in1_input",
+						contents: "3384",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/in1_label",
+						contents: "3VSB",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/in1_max",
+						contents: "6120",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/intrusion0_alarm",
+						contents: "1",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/temp1_alarm",
+						contents: "0",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/temp1_beep",
+						contents: "1",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/temp1_input",
+						contents: "43000",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/temp1_max",
+						contents: "127000",
+					},
+					{
+						name:     "/sys/devices/platform/it87.2608/temp1_type",
+						contents: "4",
+					},
+				},
+			},
+			devices: []*Device{{
+				Name: "it8728-00",
+				Sensors: []Sensor{
+					&FanSensor{
+						Name:    "fan1",
+						Alarm:   false,
+						Beep:    true,
+						Input:   1010,
+						Minimum: 10,
+					},
+					&VoltageSensor{
+						Name:    "in0",
+						Alarm:   false,
+						Beep:    false,
+						Input:   1.056,
+						Maximum: 3.060,
+					},
+					&VoltageSensor{
+						Name:    "in1",
+						Label:   "3VSB",
+						Alarm:   false,
+						Beep:    false,
+						Input:   3.384,
+						Maximum: 6.120,
+					},
+					&IntrusionSensor{
+						Name:  "intrusion0",
+						Alarm: true,
+					},
+					&TemperatureSensor{
+						Name:  "temp1",
+						Alarm: false,
+						Beep:  true,
+						Type:  TemperatureSensorTypeThermistor,
+						Input: 43.0,
+						High:  127.0,
+					},
+				},
+			}},
+		},
+		{
+			name: "multiple coretemp devices",
+			fs: &memoryFilesystem{
+				symlinks: map[string]string{
+					"/sys/class/hwmon/hwmon1":                              "../../devices/platform/coretemp.0/hwmon/hwmon1",
+					"/sys/class/hwmon/hwmon2":                              "../../devices/platform/coretemp.1/hwmon/hwmon2",
+					"/sys/devices/platform/coretemp.0/hwmon/hwmon1/device": "../../../coretemp.0",
+					"/sys/devices/platform/coretemp.1/hwmon/hwmon2/device": "../../../coretemp.1",
+				},
+				files: []memoryFile{
+					{
+						name: "/sys/class/hwmon",
+						info: &memoryFileInfo{
+							isDir: true,
+						},
+					},
+					{
+						name: "/sys/class/hwmon/hwmon1",
+						info: &memoryFileInfo{
+							mode: os.ModeSymlink,
+						},
+					},
+					{
+						name: "/sys/class/hwmon/hwmon2",
+						info: &memoryFileInfo{
+							mode: os.ModeSymlink,
+						},
+					},
+					{
+						name: "/sys/devices/platform/coretemp.0",
+						info: &memoryFileInfo{
+							isDir: true,
+						},
+					},
+					{
+						name: "/sys/devices/platform/coretemp.0/hwmon/hwmon1/name",
+						err:  os.ErrNotExist,
+					},
+					{
+						name: "/sys/devices/platform/coretemp.0/hwmon/hwmon1/device",
+						info: &memoryFileInfo{
+							// mode: os.ModeSymlink,
+						},
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/name",
+						contents: "coretemp",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp1_crit",
+						contents: "100000",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp1_crit_alarm",
+						contents: "0",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp1_input",
+						contents: "40000",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp1_label",
+						contents: "Core 0",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp1_max",
+						contents: "80000",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp2_crit",
+						contents: "100000",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp2_crit_alarm",
+						contents: "0",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp2_input",
+						contents: "42000",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp2_label",
+						contents: "Core 1",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.0/temp2_max",
+						contents: "80000",
+					},
+					{
+						name: "/sys/devices/platform/coretemp.1",
+						info: &memoryFileInfo{
+							isDir: true,
+						},
+					},
+					{
+						name: "/sys/devices/platform/coretemp.1/hwmon/hwmon2/name",
+						err:  os.ErrNotExist,
+					},
+					{
+						name: "/sys/devices/platform/coretemp.1/hwmon/hwmon2/device",
+						info: &memoryFileInfo{
+							// mode: os.ModeSymlink,
+						},
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.1/name",
+						contents: "coretemp",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.1/temp1_crit",
+						contents: "100000",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.1/temp1_crit_alarm",
+						contents: "0",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.1/temp1_input",
+						contents: "38000",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.1/temp1_label",
+						contents: "Core 0",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.1/temp1_max",
+						contents: "80000",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.1/temp2_crit",
+						contents: "100000",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.1/temp2_crit_alarm",
+						contents: "0",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.1/temp2_input",
+						contents: "37000",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.1/temp2_label",
+						contents: "Core 1",
+					},
+					{
+						name:     "/sys/devices/platform/coretemp.1/temp2_max",
+						contents: "80000",
+					},
+				},
+			},
+			devices: []*Device{
+				{
+					Name: "coretemp-00",
+					Sensors: []Sensor{
+						&TemperatureSensor{
+							Name:          "temp1",
+							Label:         "Core 0",
+							Input:         40.0,
+							High:          80.0,
+							Critical:      100.0,
+							CriticalAlarm: false,
+						},
+						&TemperatureSensor{
+							Name:          "temp2",
+							Label:         "Core 1",
+							Input:         42.0,
+							High:          80.0,
+							Critical:      100.0,
+							CriticalAlarm: false,
+						},
+					},
+				},
+				{
+					Name: "coretemp-01",
+					Sensors: []Sensor{
+						&TemperatureSensor{
+							Name:          "temp1",
+							Label:         "Core 0",
+							Input:         38.0,
+							High:          80.0,
+							Critical:      100.0,
+							CriticalAlarm: false,
+						},
+						&TemperatureSensor{
+							Name:          "temp2",
+							Label:         "Core 1",
+							Input:         37.0,
+							High:          80.0,
+							Critical:      100.0,
+							CriticalAlarm: false,
+						},
+					},
+				},
+			},
+		},
+		{
+			name: "sfc device",
+			fs: &memoryFilesystem{
+				symlinks: map[string]string{
+					"/sys/class/hwmon/hwmon0": "../../devices/pci0000:00/0000:00:02.0/0000:03:00.0/hwmon/hwmon0",
+					"/sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/hwmon/hwmon0/device": "../../../0000:03:00.0",
+				},
+				files: []memoryFile{
+					{
+						name: "/sys/class/hwmon",
+						info: &memoryFileInfo{
+							isDir: true,
+						},
+					},
+					{
+						name: "/sys/class/hwmon/hwmon0",
+						info: &memoryFileInfo{
+							mode: os.ModeSymlink,
+						},
+					},
+					{
+						name: "/sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0",
+						info: &memoryFileInfo{
+							isDir: true,
+						},
+					},
+					{
+						name: "/sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/hwmon/hwmon0/name",
+						err:  os.ErrNotExist,
+					},
+					{
+						name: "/sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/hwmon/hwmon0/device",
+						info: &memoryFileInfo{
+							// mode: os.ModeSymlink,
+						},
+					},
+					{
+						name:     "/sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/name",
+						contents: "sfc",
+					},
+					{
+						name:     "/sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/curr1_alarm",
+						contents: "0",
+					},
+					{
+						name:     "/sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/curr1_crit",
+						contents: "18000",
+					},
+					{
+						name:     "/sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/curr1_input",
+						contents: "7624",
+					},
+					{
+						name:     "/sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/curr1_label",
+						contents: "0.9V supply current",
+					},
+					{
+						name:     "/sys/devices/pci0000:00/0000:00:02.0/0000:03:00.0/curr1_max",
+						contents: "16000",
+					},
+				},
+			},
+			devices: []*Device{{
+				Name: "sfc-00",
+				Sensors: []Sensor{
+					&CurrentSensor{
+						Name:     "curr1",
+						Label:    "0.9V supply current",
+						Alarm:    false,
+						Input:    7.624,
+						Maximum:  16.0,
+						Critical: 18.0,
+					},
+				},
+			}},
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			s := &Scanner{fs: tt.fs}
+
+			devices, err := s.Scan()
+			if err != nil {
+				t.Fatalf("unexpected error: %v", err)
+			}
+
+			if want, got := tt.devices, devices; !reflect.DeepEqual(want, got) {
+				t.Fatalf("unexpected Devices:\n- want:\n%v\n-  got:\n%v",
+					devicesStr(want), devicesStr(got))
+			}
+		})
+	}
+}
+
+func devicesStr(ds []*Device) string {
+	var out string
+	for _, d := range ds {
+		out += fmt.Sprintf("device: %q [%d sensors]\n", d.Name, len(d.Sensors))
+
+		for _, s := range d.Sensors {
+			out += fmt.Sprintf("  - sensor: %#v\n", s)
+		}
+	}
+
+	return out
+}
+
+var _ filesystem = &memoryFilesystem{}
+
+// A memoryFilesystem is an in-memory implementation of filesystem, used for
+// tests.
+type memoryFilesystem struct {
+	symlinks map[string]string
+	files    []memoryFile
+}
+
+func (fs *memoryFilesystem) ReadFile(filename string) (string, error) {
+	for _, f := range fs.files {
+		if f.name == filename {
+			return f.contents, nil
+		}
+	}
+
+	return "", fmt.Errorf("readfile: file %q not in memory", filename)
+}
+
+func (fs *memoryFilesystem) Readlink(name string) (string, error) {
+	if l, ok := fs.symlinks[name]; ok {
+		return l, nil
+	}
+
+	return "", fmt.Errorf("readlink: symlink %q not in memory", name)
+}
+
+func (fs *memoryFilesystem) Stat(name string) (os.FileInfo, error) {
+	for _, f := range fs.files {
+		if f.name == name {
+			info := f.info
+			if info == nil {
+				info = &memoryFileInfo{}
+			}
+
+			return info, f.err
+		}
+	}
+
+	return nil, fmt.Errorf("stat: file %q not in memory", name)
+}
+
+func (fs *memoryFilesystem) Walk(root string, walkFn filepath.WalkFunc) error {
+	if _, err := fs.Stat(root); err != nil {
+		return err
+	}
+
+	for _, f := range fs.files {
+		// Only walk paths under the specified root
+		if !strings.HasPrefix(f.name, root) {
+			continue
+		}
+
+		info := f.info
+		if info == nil {
+			info = &memoryFileInfo{}
+		}
+
+		if err := walkFn(f.name, info, nil); err != nil {
+			return err
+		}
+	}
+
+	return nil
+}
+
+// A memoryFile is an in-memory file used by memoryFilesystem.
+type memoryFile struct {
+	name     string
+	contents string
+	info     os.FileInfo
+	err      error
+}
+
+var _ os.FileInfo = &memoryFileInfo{}
+
+// A memoryFileInfo is an os.FileInfo used by memoryFiles.
+type memoryFileInfo struct {
+	name    string
+	size    int64
+	mode    os.FileMode
+	modTime time.Time
+	isDir   bool
+}
+
+func (fi *memoryFileInfo) Name() string       { return fi.name }
+func (fi *memoryFileInfo) Size() int64        { return fi.size }
+func (fi *memoryFileInfo) Mode() os.FileMode  { return fi.mode }
+func (fi *memoryFileInfo) ModTime() time.Time { return fi.modTime }
+func (fi *memoryFileInfo) IsDir() bool        { return fi.isDir }
+func (fi *memoryFileInfo) Sys() interface{}   { return nil }

Some files were not shown because too many files changed in this diff