cc-metric-collector/collectors/infinibandMetric.go

65 lines
1.2 KiB
Go
Raw Normal View History

2021-03-25 15:55:06 +01:00
package collectors
import (
"fmt"
"io/ioutil"
"log"
"os/exec"
"strconv"
2021-03-25 17:47:08 +01:00
"strings"
2021-03-25 15:55:06 +01:00
"time"
)
const LIDFILE = `/sys/class/infiniband/mlx4_0/ports/1/lid`
type InfinibandCollector struct {
MetricCollector
}
func (m *InfinibandCollector) Init() {
2021-03-25 17:47:08 +01:00
m.name = "InfinibandCollector"
2021-03-25 15:55:06 +01:00
m.setup()
}
2021-03-25 17:47:08 +01:00
func (m *InfinibandCollector) Read(interval time.Duration) {
2021-03-25 15:55:06 +01:00
buffer, err := ioutil.ReadFile(string(LIDFILE))
if err != nil {
log.Print(err)
return
}
2021-03-25 17:47:08 +01:00
2021-03-25 15:55:06 +01:00
args := fmt.Sprintf("-r %s 1 0xf000", string(buffer))
2021-03-25 17:47:08 +01:00
2021-03-25 15:55:06 +01:00
command := exec.Command("/usr/sbin/perfquery", args)
command.Wait()
stdout, err := command.Output()
if err != nil {
2021-03-25 17:47:08 +01:00
log.Print(err)
2021-03-25 15:55:06 +01:00
return
}
ll := strings.Split(string(stdout), "\n")
for _, line := range ll {
2021-03-25 17:47:08 +01:00
if strings.HasPrefix(line, "PortRcvData") || strings.HasPrefix(line, "RcvData") {
lv := strings.Fields(line)
v, err := strconv.ParseFloat(lv[1], 64)
if err == nil {
m.node["ib_recv"] = float64(v)
}
}
2021-03-25 15:55:06 +01:00
if strings.HasPrefix(line, "PortXmitData") || strings.HasPrefix(line, "XmtData") {
2021-03-25 17:47:08 +01:00
lv := strings.Fields(line)
v, err := strconv.ParseFloat(lv[1], 64)
if err == nil {
m.node["ib_xmit"] = float64(v)
}
}
2021-03-25 15:55:06 +01:00
}
}
func (m *InfinibandCollector) Close() {
2021-03-25 17:47:08 +01:00
return
2021-03-25 15:55:06 +01:00
}