forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
infiniband_linux.go
59 lines (45 loc) · 1.27 KB
/
infiniband_linux.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
52
53
54
55
56
57
58
59
// +build linux
package infiniband
import (
"fmt"
"github.com/Mellanox/rdmamap"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
"strconv"
)
// Gather statistics from our infiniband cards
func (_ *Infiniband) Gather(acc telegraf.Accumulator) error {
rdmaDevices := rdmamap.GetRdmaDeviceList()
if len(rdmaDevices) == 0 {
return fmt.Errorf("no InfiniBand devices found in /sys/class/infiniband/")
}
for _, dev := range rdmaDevices {
devicePorts := rdmamap.GetPorts(dev)
for _, port := range devicePorts {
portInt, err := strconv.Atoi(port)
if err != nil {
return err
}
stats, err := rdmamap.GetRdmaSysfsStats(dev, portInt)
if err != nil {
return err
}
addStats(dev, port, stats, acc)
}
}
return nil
}
// Add the statistics to the accumulator
func addStats(dev string, port string, stats []rdmamap.RdmaStatEntry, acc telegraf.Accumulator) {
// Allow users to filter by card and port
tags := map[string]string{"device": dev, "port": port}
fields := make(map[string]interface{})
for _, entry := range stats {
fields[entry.Name] = entry.Value
}
acc.AddFields("infiniband", fields, tags)
}
// Initialise plugin
func init() {
inputs.Add("infiniband", func() telegraf.Input { return &Infiniband{} })
}