telegraf/plugins/inputs/temp/temp.go

51 lines
1.0 KiB
Go
Raw Normal View History

2018-09-10 18:52:15 +00:00
package temp
import (
"fmt"
"strings"
2018-09-10 18:52:15 +00:00
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
"github.com/influxdata/telegraf/plugins/inputs/system"
)
type Temperature struct {
ps system.PS
}
func (t *Temperature) Description() string {
return "Read metrics about temperature"
}
const sampleConfig = ""
func (t *Temperature) SampleConfig() string {
return sampleConfig
}
func (t *Temperature) Gather(acc telegraf.Accumulator) error {
temps, err := t.ps.Temperature()
if err != nil {
if strings.Contains(err.Error(), "not implemented yet") {
return fmt.Errorf("plugin is not supported on this platform: %v", err)
}
2018-09-10 18:52:15 +00:00
return fmt.Errorf("error getting temperatures info: %s", err)
}
for _, temp := range temps {
tags := map[string]string{
"sensor": temp.SensorKey,
}
fields := map[string]interface{}{
"temp": temp.Temperature,
}
acc.AddFields("temp", fields, tags)
}
return nil
}
func init() {
inputs.Add("temp", func() telegraf.Input {
return &Temperature{ps: system.NewSystemPS()}
})
}