https://github.com/mt-inside/go-lmsensors
Linux hardware sensor monitoring in Go
https://github.com/mt-inside/go-lmsensors
lmsensors sensors temperature-monitoring temperature-sensor
Last synced: 5 months ago
JSON representation
Linux hardware sensor monitoring in Go
- Host: GitHub
- URL: https://github.com/mt-inside/go-lmsensors
- Owner: mt-inside
- License: apache-2.0
- Created: 2021-02-27T05:02:47.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-02-06T11:46:58.000Z (over 2 years ago)
- Last Synced: 2026-01-14T19:39:53.898Z (5 months ago)
- Topics: lmsensors, sensors, temperature-monitoring, temperature-sensor
- Language: Go
- Homepage:
- Size: 49.8 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-lmsensors
Linux hardware sensor monitoring in Go.
[](https://github.com/mt-inside/go-lmsensors/actions/workflows/checks.yaml)
[](https://github.com/mt-inside/go-lmsensors/issues)
[](https://pkg.go.dev/github.com/mt-inside/go-lmsensors)
Uses the [lm-sensors](https://github.com/lm-sensors/lm-sensors) (linux monitoring sensors) pacakge, on top of the [hwmon](https://hwmon.wiki.kernel.org) kernel feature.
## Setup
* Install _lm-sensors_
* Ubuntu: `sudo apt install lm-sensors libsensors-dev`
* Arch: `pacman -S lm_sensors`
* Configure _lm-sensors_
* Run `sensors-detect`
* Make any [necessary adjustments](https://hwmon.wiki.kernel.org/faq) to the [configuration](https://linux.die.net/man/5/sensors3.conf) in `/etc/sensors3.conf`, using `/etc/sensors.d/*`
* `go get github.com/mt-inside/go-lmsensors`
## How it works
This module links against the C-language `libsensors` and calls it to get sensor readings from the hwmon kernel subsystem (which it reads from sysfs).
My original version ran and parsed `sensors -j`, as all the information is in that JSON if you really squint and know how to read it.
However, using the library direct seemed faster, avoids a fork(), and doesn't require `lm-sensors` to be installed, just `libsensors5` (some package managers have them separately). (The instructions say to install lm-sensors, becuase you almost certainly want to run `sensors-detect`.)
The hwmon data _are_ exposed through sysfs, but those are raw values - libsensors isn't just a convenience binding; it scales raw values according to a big built-in database, and lets the user rename sensors.
## Example
### Code
```go
package main
import (
"fmt"
"log"
"github.com/mt-inside/go-lmsensors"
)
func main() {
sensors, err := golmsensors.Get(true, true)
if err != nil {
log.Fatalf("Can't get sensor readings: %v", err)
}
for _, chip := range sensors.ChipsList {
fmt.Println(chip.ID)
for _, reading := range chip.SensorsList {
fmt.Printf(" [%s] %s: %s\n", reading.SensorType, reading.Name, reading.Value)
}
}
}
```
### Output
```
it8792-isa-0a60
[In] PM_CLDO12: 1.504000
[Fan] SYS_FAN4: 0.000000
[In] VIN0: 1.788000
[In] DDR VTT: 0.665000
[In] Chipset Core: 1.090000
[In] six: 2.780000
[Temp] PCIEX4_1: 37.000000
[Temp] System2: 34.000000
...
```