gosensors

package module
v0.0.0-...-e7ab9a4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2017 License: Apache-2.0 Imports: 5 Imported by: 11

README

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
package main

import (
	"fmt"
	"github.com/ssimunic/gosensors"
)

func main() {
	sensors, err := gosensors.NewFromSystem()
	// sensors, err := gosensors.NewFromFile("/path/to/log.txt")

	if err != nil {
		panic(err)
	}

	// Sensors implements Stringer interface,
	// so code below will print out JSON
	fmt.Println(sensors)

	// Also valid
	// fmt.Println("JSON:", sensors.JSON())

	// Iterate over chips
	for chip := range sensors.Chips {
		// Iterate over entries
		for key, value := range sensors.Chips[chip] {
			// If CPU or GPU, print out
			if key == "CPU" || key == "GPU" {
				fmt.Println(key, value)
			}
		}
	}
}
Output:
{"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"}}}
CPU +65.0°C
GPU +50.0°C

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entries

type Entries map[string]string

Entries representing key, value pairs for chips. Example (JSON style): "GPU": "+56.0°C" "CPU": "+68.0°C"

type Sensors

type Sensors struct {
	Content string             `json:"-"`
	Chips   map[string]Entries `json:"chips"`
}

Sensors struct represents lm-sensors output. Content field contains string output. Chips field contains map[string]Entries. Example (JSON style):

"coretemp-isa-0000": {
	"CPU": "+60.0°C",
	"GPU": "+48.0°C",
}

func NewFromFile

func NewFromFile(path string) (*Sensors, error)

NewFromFile reads content from log file and returns constructed Sensors struct. A successful call returns err == nil.

func NewFromSystem

func NewFromSystem() (*Sensors, error)

NewFromSystem executes "sensors" system command and returns constructed Sensors struct. A successful call returns err == nil.

func (*Sensors) JSON

func (s *Sensors) JSON() string

JSON returns JSON of Sensors.

func (*Sensors) String

func (s *Sensors) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL