-
Notifications
You must be signed in to change notification settings - Fork 13
/
temp.go
51 lines (43 loc) · 1.11 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
51
package temp
import (
"context"
"fmt"
"strings"
"github.com/circonus-labs/circonus-unified-agent/cua"
"github.com/circonus-labs/circonus-unified-agent/plugins/inputs"
"github.com/circonus-labs/circonus-unified-agent/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(ctx context.Context, acc cua.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: %w", err)
}
return fmt.Errorf("error getting temperatures info: %w", 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() cua.Input {
return &Temperature{ps: system.NewSystemPS()}
})
}