forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp.go
50 lines (42 loc) · 1.03 KB
/
temp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package temp
import (
"fmt"
"strings"
"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)
}
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()}
})
}