Add a new input plugin for InfiniBand card/port statistics (#6631)
This commit is contained in:
committed by
Daniel Nelson
parent
93f149f126
commit
182104f95e
59
plugins/inputs/infiniband/infiniband_linux.go
Normal file
59
plugins/inputs/infiniband/infiniband_linux.go
Normal file
@@ -0,0 +1,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{} })
|
||||
}
|
||||
Reference in New Issue
Block a user