-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hwmon /sensors support #278
Conversation
|
||
func init() { | ||
Factories["hwmon"] = NewhwMonCollector | ||
invalidMetricChars, _ = regexp.Compile("[^a-z0-9:_]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use MustCompile
instead.
0c200cf
to
c4b2a6f
Compare
@brian-brazil @grobie I've worked through all the small bugs so can I have another 👀 plz? |
hwMonSubsystem = "hwmon" | ||
) | ||
|
||
type hwMonCollector struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Can we keep that directly over NewHwMonCollector? I usually keep that order in go: imports, global const, global var, init, type, NewType, functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meta-nit: Can you add that to the contributing docs? It doesn't look like the order is documented anywhere. Maybe even try to get this into https://github.com/golang/go/wiki/CodeReviewComments
Can you please add end-to-end tests. |
if err != nil { | ||
return err | ||
} | ||
_ = collectSensorData(path.Join(dir, "device"), data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't ignore this error
@rtreffer This is really cool! Any chance you might find time soon to address the comments here? Would love to have this in the node-exporter! |
@discordianfish yes, looked into it yesterday and thought "I should fix this". Will try to get the next round going soon. |
@rtreffer Awesome, looking forward to it! |
67f84a3
to
79ca7f4
Compare
Got interrupted yesterday, but managed to go with a split-by-regex approach and fixing all those silly tyops. Still have to build the end-to-end test, though. |
@rtreffer Not sure if you've already looked at it, but the mentioned end-to-end tests are super easy. See https://github.com/prometheus/node_exporter/blob/master/end-to-end-test.sh Just add the relevant sysfs files to https://github.com/prometheus/node_exporter/tree/master/collector/fixtures and update the expected output in https://github.com/prometheus/node_exporter/blob/master/collector/fixtures/e2e-output.txt. |
(and enable that collector in the |
79ca7f4
to
9567d18
Compare
Ok, I need at least 2 sensors as 2 layouts are possible:
Besides that it's a mix of some of the reading I got on a few machines. |
@juliusv / @brian-brazil anything else? |
continue | ||
} | ||
|
||
// fallback, just dump |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments should be full sentences.
label = sensor | ||
} | ||
} | ||
labels := []string{hwmonName, sensor, label} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we should expose both the sensor and label, just the label should do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll give it a try on a few machines, if it works with just label I'd change to that. In theory it could fail with "bad" drivers, but I'm not sure if such drivers exist (sensor is guaranteed to be unique, label not).
@brian-brazil updated. Couldn't see issue when dropping sensor, but I have only a limited sample size. |
var ( | ||
hwmonInvalidMetricChars = regexp.MustCompile("[^a-z0-9:_]") | ||
hwmonFilenameFormat = regexp.MustCompile(`^(?P<type>[^0-9]+)(?P<id>[0-9]*)?(_(?P<property>.+))?$`) | ||
hwmonLabelDesc = []string{"chip", "sensorName"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can just be sensor
now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure thing.
dad4ead
to
e65908e
Compare
@@ -31,7 +31,7 @@ import ( | |||
) | |||
|
|||
const ( | |||
defaultCollectors = "conntrack,cpu,diskstats,entropy,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname,vmstat" | |||
defaultCollectors = "conntrack,cpu,diskstats,entropy,filefd,filesystem,hwmon,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname,vmstat" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README needs updating too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's just the one-line I've added, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
This commit adds initial support for linux hardware sensors, exported through sysfs. Details of the interface can be found at https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
e65908e
to
fbcb428
Compare
So anything else? |
Thanks! |
* Add hwmon support (mainly known from lm-sensors) This commit adds initial support for linux hardware sensors, exported through sysfs. Details of the interface can be found at https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface * Add end-to-end test with some real life data * Cleanup comments on hwmon collector * Drop raw sensor name from hwmon output * Let the sensor label be "sensor" * Add hwmon short description to README.
This commit adds initial support for linux hardware sensors, exported through sysfs.
This data is commonly read via lm-sensors
sensors
commandDetails of the interface can be found at https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
Sensor data is exported as
node_hwmon_<sensor_type><sensor_element>
e.g. node_hwmon_temp_celsius
All extra information, like the original sensor, the input within the sensor and the possible input name are exported as labels.
Reading the data does not require any special permissions (I'm running this as my linux normal user).
On my home machine this exports (full paste at http://pastebin.com/7TR6KKVM )
On my laptop I get e.g.
The workflow to generate the data is
3.a) read the hwmon ./ folder
3.b) read the hwmon device/ folder
3.c) Dump as prometheus metrics, adding types if known (most of the updateHwmon method)
This patch will most likely need a cleanup (it is too large & could need some tests etc), but I'm opening the PR for discussion as this starts to look interesting and #211 mentions temperature data.