mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-11-10 12:37:25 +01:00
8d85bd53f1
* Cleanup: Remove unused code * Use Golang duration parser for 'interval' and 'duration' in main config * Update handling of LIKWID headers. Download only if not already present in the system. Fixes #73 * Units with cc-units (#64) * Add option to normalize units with cc-unit * Add unit conversion to router * Add option to change unit prefix in the router * Add to MetricRouter README * Add order of operations in router to README * Use second add_tags/del_tags only if metric gets renamed * Skip disks in DiskstatCollector that have size=0 * Check readability of sensor files in TempCollector * Fix for --once option * Rename `cpu` type to `hwthread` (#69) * Rename 'cpu' type to 'hwthread' to avoid naming clashes with MetricStore and CC-Webfrontend * Collectors in parallel (#74) * Provide info to CollectorManager whether the collector can be executed in parallel with others * Split serial and parallel collectors. Read in parallel first * Update NvidiaCollector with new metrics, MIG and NvLink support (#75) * CC topology module update (#76) * Rename CPU to hardware thread, write some comments * Do renaming in other parts * Remove CpuList and SocketList function from metricCollector. Available in ccTopology * Option to use MIG UUID as subtype-id in NvidiaCollector * Option to use MIG slice name as subtype-id in NvidiaCollector * MetricRouter: Fix JSON in README * Fix for Github Action to really use the selected version * Remove Ganglia installation in runonce Action and add Go 1.18 * Fix daemon options in init script * Add separate go.mod files to use it with deprecated 1.16 * Minor updates for Makefiles * fix string comparison * AMD ROCm SMI collector (#77) * Add collector for AMD ROCm SMI metrics * Fix import path * Fix imports * Remove Board Number * store GPU index explicitly * Remove board number from description * Use http instead of ftp to download likwid * Fix serial number in rocmCollector * Improved http sink (#78) * automatic flush in NatsSink * tweak default options of HttpSink * shorter cirt. section and retries for HttpSink * fix error handling * Remove file added by mistake. * Use http instead of ftp to download likwid * Fix serial number in rocmCollector Co-authored-by: Thomas Roehl <thomas.roehl@fau.de> Co-authored-by: Holger Obermaier <40787752+ho-ob@users.noreply.github.com> Co-authored-by: Lou <lou.knauer@gmx.de>
223 lines
5.9 KiB
Go
223 lines
5.9 KiB
Go
package collectors
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
|
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
|
"golang.org/x/sys/unix"
|
|
|
|
"encoding/json"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const IB_BASEPATH = "/sys/class/infiniband/"
|
|
|
|
type InfinibandCollectorMetric struct {
|
|
path string
|
|
unit string
|
|
}
|
|
|
|
type InfinibandCollectorInfo struct {
|
|
LID string // IB local Identifier (LID)
|
|
device string // IB device
|
|
port string // IB device port
|
|
portCounterFiles map[string]InfinibandCollectorMetric // mapping counter name -> InfinibandCollectorMetric
|
|
tagSet map[string]string // corresponding tag list
|
|
lastState map[string]int64 // State from last measurement
|
|
}
|
|
|
|
type InfinibandCollector struct {
|
|
metricCollector
|
|
config struct {
|
|
ExcludeDevices []string `json:"exclude_devices,omitempty"` // IB device to exclude e.g. mlx5_0
|
|
SendAbsoluteValues bool `json:"send_abs_values"` // Send absolut values as read from sys filesystem
|
|
SendDerivedValues bool `json:"send_derived_values"` // Send derived values e.g. rates
|
|
}
|
|
info []*InfinibandCollectorInfo
|
|
lastTimestamp time.Time // Store time stamp of last tick to derive bandwidths
|
|
}
|
|
|
|
// Init initializes the Infiniband collector by walking through files below IB_BASEPATH
|
|
func (m *InfinibandCollector) Init(config json.RawMessage) error {
|
|
|
|
// Check if already initialized
|
|
if m.init {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
m.name = "InfinibandCollector"
|
|
m.setup()
|
|
m.parallel = true
|
|
m.meta = map[string]string{
|
|
"source": m.name,
|
|
"group": "Network",
|
|
}
|
|
|
|
// Set default configuration,
|
|
m.config.SendAbsoluteValues = true
|
|
m.config.SendDerivedValues = false
|
|
// Read configuration file, allow overwriting default config
|
|
if len(config) > 0 {
|
|
err = json.Unmarshal(config, &m.config)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
// Loop for all InfiniBand directories
|
|
globPattern := filepath.Join(IB_BASEPATH, "*", "ports", "*")
|
|
ibDirs, err := filepath.Glob(globPattern)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to glob files with pattern %s: %v", globPattern, err)
|
|
}
|
|
if ibDirs == nil {
|
|
return fmt.Errorf("unable to find any directories with pattern %s", globPattern)
|
|
}
|
|
|
|
for _, path := range ibDirs {
|
|
|
|
// Skip, when no LID is assigned
|
|
line, err := ioutil.ReadFile(filepath.Join(path, "lid"))
|
|
if err != nil {
|
|
continue
|
|
}
|
|
LID := strings.TrimSpace(string(line))
|
|
if LID == "0x0" {
|
|
continue
|
|
}
|
|
|
|
// Get device and port component
|
|
pathSplit := strings.Split(path, string(os.PathSeparator))
|
|
device := pathSplit[4]
|
|
port := pathSplit[6]
|
|
|
|
// Skip excluded devices
|
|
skip := false
|
|
for _, excludedDevice := range m.config.ExcludeDevices {
|
|
if excludedDevice == device {
|
|
skip = true
|
|
break
|
|
}
|
|
}
|
|
if skip {
|
|
continue
|
|
}
|
|
|
|
// Check access to counter files
|
|
countersDir := filepath.Join(path, "counters")
|
|
portCounterFiles := map[string]InfinibandCollectorMetric{
|
|
"ib_recv": {path: filepath.Join(countersDir, "port_rcv_data"), unit: "bytes"},
|
|
"ib_xmit": {path: filepath.Join(countersDir, "port_xmit_data"), unit: "bytes"},
|
|
"ib_recv_pkts": {path: filepath.Join(countersDir, "port_rcv_packets"), unit: "packets"},
|
|
"ib_xmit_pkts": {path: filepath.Join(countersDir, "port_xmit_packets"), unit: "packets"},
|
|
}
|
|
for _, counter := range portCounterFiles {
|
|
err := unix.Access(counter.path, unix.R_OK)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to access %s: %v", counter.path, err)
|
|
}
|
|
}
|
|
|
|
// Initialize last state
|
|
lastState := make(map[string]int64)
|
|
for counter := range portCounterFiles {
|
|
lastState[counter] = -1
|
|
}
|
|
|
|
m.info = append(m.info,
|
|
&InfinibandCollectorInfo{
|
|
LID: LID,
|
|
device: device,
|
|
port: port,
|
|
portCounterFiles: portCounterFiles,
|
|
tagSet: map[string]string{
|
|
"type": "node",
|
|
"device": device,
|
|
"port": port,
|
|
"lid": LID,
|
|
},
|
|
lastState: lastState,
|
|
})
|
|
}
|
|
|
|
if len(m.info) == 0 {
|
|
return fmt.Errorf("found no IB devices")
|
|
}
|
|
|
|
m.init = true
|
|
return nil
|
|
}
|
|
|
|
// Read reads Infiniband counter files below IB_BASEPATH
|
|
func (m *InfinibandCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|
|
|
// Check if already initialized
|
|
if !m.init {
|
|
return
|
|
}
|
|
|
|
// Current time stamp
|
|
now := time.Now()
|
|
// time difference to last time stamp
|
|
timeDiff := now.Sub(m.lastTimestamp).Seconds()
|
|
// Save current timestamp
|
|
m.lastTimestamp = now
|
|
|
|
for _, info := range m.info {
|
|
for counterName, counterDef := range info.portCounterFiles {
|
|
|
|
// Read counter file
|
|
line, err := ioutil.ReadFile(counterDef.path)
|
|
if err != nil {
|
|
cclog.ComponentError(
|
|
m.name,
|
|
fmt.Sprintf("Read(): Failed to read from file '%s': %v", counterDef.path, err))
|
|
continue
|
|
}
|
|
data := strings.TrimSpace(string(line))
|
|
|
|
// convert counter to int64
|
|
v, err := strconv.ParseInt(data, 10, 64)
|
|
if err != nil {
|
|
cclog.ComponentError(
|
|
m.name,
|
|
fmt.Sprintf("Read(): Failed to convert Infininiband metrice %s='%s' to int64: %v", counterName, data, err))
|
|
continue
|
|
}
|
|
|
|
// Send absolut values
|
|
if m.config.SendAbsoluteValues {
|
|
if y, err := lp.New(counterName, info.tagSet, m.meta, map[string]interface{}{"value": v}, now); err == nil {
|
|
y.AddMeta("unit", counterDef.unit)
|
|
output <- y
|
|
}
|
|
}
|
|
|
|
// Send derived values
|
|
if m.config.SendDerivedValues {
|
|
if info.lastState[counterName] >= 0 {
|
|
rate := float64((v - info.lastState[counterName])) / timeDiff
|
|
if y, err := lp.New(counterName+"_bw", info.tagSet, m.meta, map[string]interface{}{"value": rate}, now); err == nil {
|
|
y.AddMeta("unit", counterDef.unit+"/sec")
|
|
output <- y
|
|
}
|
|
}
|
|
// Save current state
|
|
info.lastState[counterName] = v
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
func (m *InfinibandCollector) Close() {
|
|
m.init = false
|
|
}
|