forked from netdata/netdata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
13 changed files
with
1,543 additions
and
172 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
lmsensors [](https://travis-ci.org/mdlayher/lmsensors) [](http://godoc.org/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
62
src/go/plugin/go.d/modules/sensors/lmsensors/currentsensor.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
src/go/plugin/go.d/modules/sensors/lmsensors/intrusionsensor.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
72
src/go/plugin/go.d/modules/sensors/lmsensors/powersensor.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.