2018-09-10 18:52:15 +00:00
|
|
|
package temp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-09-27 02:05:55 +00:00
|
|
|
"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 {
|
2018-09-27 02:05:55 +00:00
|
|
|
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()}
|
|
|
|
})
|
|
|
|
}
|