mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-11-10 04:27:25 +01:00
Add InfinibandCollector
This commit is contained in:
parent
5659607993
commit
642314c102
64
collectors/infinibandMetric.go
Normal file
64
collectors/infinibandMetric.go
Normal file
@ -0,0 +1,64 @@
|
||||
package collectors
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const LIDFILE = `/sys/class/infiniband/mlx4_0/ports/1/lid`
|
||||
|
||||
type InfinibandCollector struct {
|
||||
MetricCollector
|
||||
}
|
||||
|
||||
func (m *InfinibandCollector) Init() {
|
||||
m.name = "InfinibandCollector"
|
||||
m.setup()
|
||||
}
|
||||
|
||||
func (m *InfinibandCollector) Read(interval time.Duration){
|
||||
buffer, err := ioutil.ReadFile(string(LIDFILE))
|
||||
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return
|
||||
}
|
||||
|
||||
args := fmt.Sprintf("-r %s 1 0xf000", string(buffer))
|
||||
|
||||
command := exec.Command("/usr/sbin/perfquery", args)
|
||||
command.Wait()
|
||||
stdout, err := command.Output()
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return
|
||||
}
|
||||
|
||||
ll := strings.Split(string(stdout), "\n")
|
||||
|
||||
for _, line := range ll {
|
||||
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)
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(line, "PortXmitData") || strings.HasPrefix(line, "XmtData") {
|
||||
lv := strings.Fields(line)
|
||||
v, err := strconv.ParseFloat(lv[1], 64)
|
||||
if err == nil {
|
||||
m.node["ib_xmit"] = float64(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *InfinibandCollector) Close() {
|
||||
return
|
||||
}
|
@ -11,7 +11,8 @@
|
||||
"memstat",
|
||||
"likwid",
|
||||
"loadavg",
|
||||
"netstat"
|
||||
"netstat",
|
||||
"ibstat"
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ var Collectors = map[string]collectors.MetricGetter{
|
||||
"loadavg": &collectors.LoadavgCollector{},
|
||||
"memstat": &collectors.MemstatCollector{},
|
||||
"netstat": &collectors.NetstatCollector{},
|
||||
"ibstat": &collectors.InfinibandCollector{},
|
||||
}
|
||||
type GlobalConfig struct {
|
||||
Sink struct {
|
||||
|
Loading…
Reference in New Issue
Block a user