项目作者: ssimunic

项目描述 :
Hardware sensors using Go and lm-sensors
高级语言: Go
项目地址: git://github.com/ssimunic/gosensors.git
创建时间: 2017-03-09T16:46:39Z
项目社区:https://github.com/ssimunic/gosensors

开源协议:Apache License 2.0

下载


gosensors

GoDoc

Hardware sensors using Go and lm-sensors

Setup

  • Install lm-sensors with sudo apt get install lm-sensors
  • go get github.com/ssimunic/gosensors in your working directory

Example

Program

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/ssimunic/gosensors"
  5. )
  6. func main() {
  7. sensors, err := gosensors.NewFromSystem()
  8. // sensors, err := gosensors.NewFromFile("/path/to/log.txt")
  9. if err != nil {
  10. panic(err)
  11. }
  12. // Sensors implements Stringer interface,
  13. // so code below will print out JSON
  14. fmt.Println(sensors)
  15. // Also valid
  16. // fmt.Println("JSON:", sensors.JSON())
  17. // Iterate over chips
  18. for chip := range sensors.Chips {
  19. // Iterate over entries
  20. for key, value := range sensors.Chips[chip] {
  21. // If CPU or GPU, print out
  22. if key == "CPU" || key == "GPU" {
  23. fmt.Println(key, value)
  24. }
  25. }
  26. }
  27. }

Output:

  1. {"chips":{"acpitz-virtual-0":{"Adapter":"Virtual device","temp1":"+25.0°C (crit = +107.0°C)"},"coretemp-isa-0000":{"Adapter":"ISA adapter","Core 0":"+76.0°C (high = +105.0°C, crit = +105.0°C)","Core 1":"+74.0°C (high = +105.0°C, crit = +105.0°C)","Physical id 0":"+76.0°C (high = +105.0°C, crit = +105.0°C)"},"dell_smm-virtual-0":{"Adapter":"Virtual device","CPU":"+65.0°C","GPU":"+50.0°C","Other":"+50.0°C","Processor Fan":"2200 RPM","SODIMM":"+39.0°C","fan2":"2200 RPM"}}}
  2. CPU +65.0°C
  3. GPU +50.0°C