Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 authored Aug 28, 2024
1 parent 3aa4603 commit 01ce883
Show file tree
Hide file tree
Showing 13 changed files with 1,543 additions and 172 deletions.
206 changes: 34 additions & 172 deletions REDISTRIBUTED.md

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/go/plugin/go.d/modules/sensors/lmsensors/LICENSE.md
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions src/go/plugin/go.d/modules/sensors/lmsensors/README.md
Original file line number Diff line number Diff line change
@@ -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 changes: 62 additions & 0 deletions src/go/plugin/go.d/modules/sensors/lmsensors/currentsensor.go
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions src/go/plugin/go.d/modules/sensors/lmsensors/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package lmsensors provides access to Linux monitoring sensors data, such
// as temperatures, voltage, and fan speeds.
package lmsensors
55 changes: 55 additions & 0 deletions src/go/plugin/go.d/modules/sensors/lmsensors/fansensor.go
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions src/go/plugin/go.d/modules/sensors/lmsensors/intrusionsensor.go
Original file line number Diff line number Diff line change
@@ -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 changes: 72 additions & 0 deletions src/go/plugin/go.d/modules/sensors/lmsensors/powersensor.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading

0 comments on commit 01ce883

Please sign in to comment.