2016-01-15 20:15:33 +00:00
|
|
|
// +build linux,sensors
|
2016-01-15 12:21:49 +00:00
|
|
|
|
2016-01-14 23:03:39 +00:00
|
|
|
package sensors
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/md14454/gosensors"
|
|
|
|
|
2016-01-20 20:19:03 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/inputs"
|
2016-01-14 23:03:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Sensors struct {
|
|
|
|
Sensors []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (_ *Sensors) Description() string {
|
|
|
|
return "Monitor sensors using lm-sensors package"
|
|
|
|
}
|
|
|
|
|
|
|
|
var sensorsSampleConfig = `
|
2016-01-15 18:22:33 +00:00
|
|
|
# By default, telegraf gathers stats from all sensors detected by the
|
|
|
|
# lm-sensors module.
|
|
|
|
#
|
|
|
|
# Only collect stats from the selected sensors. Sensors are listed as
|
|
|
|
# <chip name>:<feature name>. This information can be found by running the
|
|
|
|
# sensors command, e.g. sensors -u
|
|
|
|
#
|
2016-01-14 23:03:39 +00:00
|
|
|
# A * as the feature name will return all features of the chip
|
|
|
|
#
|
2016-01-15 18:22:33 +00:00
|
|
|
# sensors = ["coretemp-isa-0000:Core 0", "coretemp-isa-0001:*"]
|
2016-01-14 23:03:39 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
func (_ *Sensors) SampleConfig() string {
|
|
|
|
return sensorsSampleConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Sensors) Gather(acc inputs.Accumulator) error {
|
|
|
|
gosensors.Init()
|
|
|
|
defer gosensors.Cleanup()
|
|
|
|
|
|
|
|
for _, chip := range gosensors.GetDetectedChips() {
|
|
|
|
for _, feature := range chip.GetFeatures() {
|
|
|
|
chipName := chip.String()
|
|
|
|
featureLabel := feature.GetLabel()
|
|
|
|
|
|
|
|
if len(s.Sensors) != 0 {
|
|
|
|
var found bool
|
|
|
|
|
|
|
|
for _, sensor := range s.Sensors {
|
|
|
|
parts := strings.SplitN(":", sensor, 2)
|
|
|
|
|
|
|
|
if parts[0] == chipName {
|
|
|
|
if parts[1] == "*" || parts[1] == featureLabel {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tags := map[string]string{
|
|
|
|
"chip": chipName,
|
|
|
|
"adapter": chip.AdapterName(),
|
|
|
|
"feature-name": feature.Name,
|
|
|
|
"feature-label": featureLabel,
|
|
|
|
}
|
|
|
|
|
|
|
|
fieldName := chipName + ":" + featureLabel
|
|
|
|
|
|
|
|
fields := map[string]interface{}{
|
2016-01-14 23:12:35 +00:00
|
|
|
fieldName: feature.GetValue(),
|
2016-01-14 23:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
acc.AddFields("sensors", fields, tags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
inputs.Add("sensors", func() inputs.Input {
|
|
|
|
return &Sensors{}
|
|
|
|
})
|
|
|
|
}
|