2021-03-25 14:47:10 +01:00
|
|
|
package collectors
|
2021-03-25 17:47:08 +01:00
|
|
|
|
2021-03-25 14:47:10 +01:00
|
|
|
/*
|
|
|
|
#cgo CFLAGS: -I./likwid
|
2022-03-03 13:03:58 +01:00
|
|
|
#cgo LDFLAGS: -Wl,--unresolved-symbols=ignore-in-object-files
|
2021-03-25 14:47:10 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <likwid.h>
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
2021-11-25 15:11:39 +01:00
|
|
|
"encoding/json"
|
2021-03-25 14:47:10 +01:00
|
|
|
"errors"
|
2021-03-25 17:47:08 +01:00
|
|
|
"fmt"
|
2021-11-25 15:11:39 +01:00
|
|
|
"io/ioutil"
|
|
|
|
"math"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
2021-03-25 14:47:10 +01:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"unsafe"
|
2022-02-01 16:01:31 +01:00
|
|
|
|
|
|
|
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
2022-01-25 15:37:43 +01:00
|
|
|
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
2022-02-01 16:01:31 +01:00
|
|
|
topo "github.com/ClusterCockpit/cc-metric-collector/internal/ccTopology"
|
2022-02-03 16:52:55 +01:00
|
|
|
agg "github.com/ClusterCockpit/cc-metric-collector/internal/metricAggregator"
|
2022-02-21 13:29:33 +01:00
|
|
|
"github.com/NVIDIA/go-nvml/pkg/dl"
|
2021-03-25 14:47:10 +01:00
|
|
|
)
|
|
|
|
|
2022-02-21 13:29:33 +01:00
|
|
|
const (
|
2022-03-03 13:03:58 +01:00
|
|
|
LIKWID_LIB_NAME = "liblikwid.so"
|
|
|
|
LIKWID_LIB_DL_FLAGS = dl.RTLD_LAZY | dl.RTLD_GLOBAL
|
|
|
|
LIKWID_DEF_ACCESSMODE = "direct"
|
2022-02-21 13:29:33 +01:00
|
|
|
)
|
|
|
|
|
2021-11-25 14:04:03 +01:00
|
|
|
type LikwidCollectorMetricConfig struct {
|
2022-03-11 13:43:17 +01:00
|
|
|
Name string `json:"name"` // Name of the metric
|
|
|
|
Calc string `json:"calc"` // Calculation for the metric using
|
|
|
|
Type string `json:"type"` // Metric type (aka node, socket, cpu, ...)
|
|
|
|
Publish bool `json:"publish"`
|
|
|
|
Unit string `json:"unit"` // Unit of metric if any
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type LikwidCollectorEventsetConfig struct {
|
2022-03-11 13:43:17 +01:00
|
|
|
Events map[string]string `json:"events"`
|
|
|
|
Metrics []LikwidCollectorMetricConfig `json:"metrics"`
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type LikwidCollectorConfig struct {
|
2021-11-25 15:11:39 +01:00
|
|
|
Eventsets []LikwidCollectorEventsetConfig `json:"eventsets"`
|
2022-02-07 18:35:08 +01:00
|
|
|
Metrics []LikwidCollectorMetricConfig `json:"globalmetrics,omitempty"`
|
|
|
|
ForceOverwrite bool `json:"force_overwrite,omitempty"`
|
2022-02-21 13:29:33 +01:00
|
|
|
InvalidToZero bool `json:"invalid_to_zero,omitempty"`
|
2022-03-03 13:03:58 +01:00
|
|
|
AccessMode string `json:"access_mode,omitempty"`
|
|
|
|
DaemonPath string `json:"accessdaemon_path,omitempty"`
|
2022-03-11 13:43:17 +01:00
|
|
|
LibraryPath string `json:"liblikwid_path,omitempty"`
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
|
|
|
|
2021-03-25 14:47:10 +01:00
|
|
|
type LikwidCollector struct {
|
2022-01-25 15:37:43 +01:00
|
|
|
metricCollector
|
2022-03-11 13:43:17 +01:00
|
|
|
cpulist []C.int
|
|
|
|
cpu2tid map[int]int
|
|
|
|
sock2tid map[int]int
|
|
|
|
metrics map[C.int]map[string]int
|
|
|
|
groups []C.int
|
|
|
|
config LikwidCollectorConfig
|
|
|
|
results map[int]map[int]map[string]interface{}
|
|
|
|
mresults map[int]map[int]map[string]float64
|
|
|
|
gmresults map[int]map[string]float64
|
|
|
|
basefreq float64
|
|
|
|
running bool
|
2021-03-25 14:47:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type LikwidMetric struct {
|
2022-02-01 16:01:31 +01:00
|
|
|
name string
|
|
|
|
search string
|
2022-03-11 13:43:17 +01:00
|
|
|
scope string
|
2022-02-01 16:01:31 +01:00
|
|
|
group_idx int
|
2021-03-25 14:47:10 +01:00
|
|
|
}
|
|
|
|
|
2021-11-25 14:04:03 +01:00
|
|
|
func eventsToEventStr(events map[string]string) string {
|
2021-11-25 15:11:39 +01:00
|
|
|
elist := make([]string, 0)
|
|
|
|
for k, v := range events {
|
|
|
|
elist = append(elist, fmt.Sprintf("%s:%s", v, k))
|
|
|
|
}
|
|
|
|
return strings.Join(elist, ",")
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func getBaseFreq() float64 {
|
2021-11-25 15:11:39 +01:00
|
|
|
var freq float64 = math.NaN()
|
|
|
|
C.power_init(0)
|
|
|
|
info := C.get_powerInfo()
|
|
|
|
if float64(info.baseFrequency) != 0 {
|
2022-03-11 13:43:17 +01:00
|
|
|
freq = float64(info.baseFrequency) * 1e6
|
2021-11-25 15:11:39 +01:00
|
|
|
} else {
|
|
|
|
buffer, err := ioutil.ReadFile("/sys/devices/system/cpu/cpu0/cpufreq/bios_limit")
|
|
|
|
if err == nil {
|
|
|
|
data := strings.Replace(string(buffer), "\n", "", -1)
|
|
|
|
x, err := strconv.ParseInt(data, 0, 64)
|
|
|
|
if err == nil {
|
2022-03-11 13:43:17 +01:00
|
|
|
freq = float64(x) * 1e6
|
2021-11-25 15:11:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return freq
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
|
|
|
|
2022-01-25 15:37:43 +01:00
|
|
|
func (m *LikwidCollector) Init(config json.RawMessage) error {
|
2021-05-18 15:14:11 +02:00
|
|
|
var ret C.int
|
2021-03-25 17:47:08 +01:00
|
|
|
m.name = "LikwidCollector"
|
2022-03-03 13:03:58 +01:00
|
|
|
m.config.AccessMode = LIKWID_DEF_ACCESSMODE
|
2022-03-11 13:43:17 +01:00
|
|
|
m.config.LibraryPath = LIKWID_LIB_NAME
|
2021-11-25 14:04:03 +01:00
|
|
|
if len(config) > 0 {
|
2021-11-25 15:11:39 +01:00
|
|
|
err := json.Unmarshal(config, &m.config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
2022-03-11 13:43:17 +01:00
|
|
|
lib := dl.New(m.config.LibraryPath, LIKWID_LIB_DL_FLAGS)
|
2022-02-21 13:29:33 +01:00
|
|
|
if lib == nil {
|
2022-03-11 13:43:17 +01:00
|
|
|
return fmt.Errorf("error instantiating DynamicLibrary for %s", m.config.LibraryPath)
|
2022-02-21 13:29:33 +01:00
|
|
|
}
|
2022-03-03 13:03:58 +01:00
|
|
|
err := lib.Open()
|
|
|
|
if err != nil {
|
2022-03-11 13:43:17 +01:00
|
|
|
return fmt.Errorf("error opening %s: %v", m.config.LibraryPath, err)
|
2022-03-03 13:03:58 +01:00
|
|
|
}
|
|
|
|
|
2022-02-01 16:01:31 +01:00
|
|
|
if m.config.ForceOverwrite {
|
2022-02-02 14:52:07 +01:00
|
|
|
cclog.ComponentDebug(m.name, "Set LIKWID_FORCE=1")
|
2022-02-01 16:01:31 +01:00
|
|
|
os.Setenv("LIKWID_FORCE", "1")
|
|
|
|
}
|
2021-03-25 14:47:10 +01:00
|
|
|
m.setup()
|
2022-02-01 16:01:31 +01:00
|
|
|
|
2022-01-25 15:37:43 +01:00
|
|
|
m.meta = map[string]string{"source": m.name, "group": "PerfCounter"}
|
2022-02-02 14:52:07 +01:00
|
|
|
cclog.ComponentDebug(m.name, "Get cpulist and init maps and lists")
|
2022-02-01 16:01:31 +01:00
|
|
|
cpulist := topo.CpuList()
|
2021-03-25 14:47:10 +01:00
|
|
|
m.cpulist = make([]C.int, len(cpulist))
|
2022-02-02 14:52:07 +01:00
|
|
|
m.cpu2tid = make(map[int]int)
|
2021-03-25 14:47:10 +01:00
|
|
|
for i, c := range cpulist {
|
2021-03-25 17:47:08 +01:00
|
|
|
m.cpulist[i] = C.int(c)
|
2022-02-02 14:52:07 +01:00
|
|
|
m.cpu2tid[c] = i
|
2022-03-16 19:04:39 +01:00
|
|
|
}
|
|
|
|
m.sock2tid = make(map[int]int)
|
|
|
|
tmp := make([]C.int, 1)
|
|
|
|
for _, sid := range topo.SocketList() {
|
|
|
|
cstr := C.CString(fmt.Sprintf("S%d:0", sid))
|
|
|
|
ret = C.cpustr_to_cpulist(cstr, &tmp[0], 1)
|
|
|
|
if ret > 0 {
|
|
|
|
m.sock2tid[sid] = m.cpu2tid[int(tmp[0])]
|
|
|
|
}
|
|
|
|
C.free(unsafe.Pointer(cstr))
|
2021-03-25 14:47:10 +01:00
|
|
|
}
|
2021-11-25 14:04:03 +01:00
|
|
|
m.results = make(map[int]map[int]map[string]interface{})
|
|
|
|
m.mresults = make(map[int]map[int]map[string]float64)
|
|
|
|
m.gmresults = make(map[int]map[string]float64)
|
2022-02-02 14:52:07 +01:00
|
|
|
cclog.ComponentDebug(m.name, "initialize LIKWID topology")
|
2021-05-18 15:14:11 +02:00
|
|
|
ret = C.topology_init()
|
|
|
|
if ret != 0 {
|
2022-02-01 16:01:31 +01:00
|
|
|
err := errors.New("failed to initialize LIKWID topology")
|
|
|
|
cclog.ComponentError(m.name, err.Error())
|
|
|
|
return err
|
2021-11-25 15:11:39 +01:00
|
|
|
}
|
2022-02-02 14:52:07 +01:00
|
|
|
|
2022-03-03 13:03:58 +01:00
|
|
|
switch m.config.AccessMode {
|
|
|
|
case "direct":
|
|
|
|
C.HPMmode(0)
|
|
|
|
case "accessdaemon":
|
|
|
|
if len(m.config.DaemonPath) > 0 {
|
|
|
|
p := os.Getenv("PATH")
|
|
|
|
os.Setenv("PATH", m.config.DaemonPath+":"+p)
|
|
|
|
}
|
|
|
|
C.HPMmode(1)
|
|
|
|
}
|
2022-02-02 14:52:07 +01:00
|
|
|
|
|
|
|
cclog.ComponentDebug(m.name, "initialize LIKWID perfmon module")
|
2021-05-18 15:14:11 +02:00
|
|
|
ret = C.perfmon_init(C.int(len(m.cpulist)), &m.cpulist[0])
|
|
|
|
if ret != 0 {
|
|
|
|
C.topology_finalize()
|
2022-02-01 16:01:31 +01:00
|
|
|
err := errors.New("failed to initialize LIKWID topology")
|
|
|
|
cclog.ComponentError(m.name, err.Error())
|
|
|
|
return err
|
2021-05-18 15:14:11 +02:00
|
|
|
}
|
2021-11-25 15:11:39 +01:00
|
|
|
|
2022-02-02 14:52:07 +01:00
|
|
|
// This is for the global metrics computation test
|
2022-02-01 16:01:31 +01:00
|
|
|
globalParams := make(map[string]interface{})
|
|
|
|
globalParams["time"] = float64(1.0)
|
|
|
|
globalParams["inverseClock"] = float64(1.0)
|
2022-02-02 14:52:07 +01:00
|
|
|
// While adding the events, we test the metrics whether they can be computed at all
|
2021-11-25 14:04:03 +01:00
|
|
|
for i, evset := range m.config.Eventsets {
|
2022-03-11 13:43:17 +01:00
|
|
|
var gid C.int
|
|
|
|
var cstr *C.char
|
|
|
|
if len(evset.Events) > 0 {
|
|
|
|
estr := eventsToEventStr(evset.Events)
|
|
|
|
// Generate parameter list for the metric computing test
|
|
|
|
params := make(map[string]interface{})
|
|
|
|
params["time"] = float64(1.0)
|
|
|
|
params["inverseClock"] = float64(1.0)
|
|
|
|
for counter := range evset.Events {
|
|
|
|
params[counter] = float64(1.0)
|
2022-02-01 16:01:31 +01:00
|
|
|
}
|
2022-03-11 13:43:17 +01:00
|
|
|
for _, metric := range evset.Metrics {
|
|
|
|
// Try to evaluate the metric
|
|
|
|
_, err := agg.EvalFloat64Condition(metric.Calc, params)
|
|
|
|
if err != nil {
|
|
|
|
cclog.ComponentError(m.name, "Calculation for metric", metric.Name, "failed:", err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// If the metric is not in the parameter list for the global metrics, add it
|
|
|
|
if _, ok := globalParams[metric.Name]; !ok {
|
|
|
|
globalParams[metric.Name] = float64(1.0)
|
|
|
|
}
|
2022-02-01 16:01:31 +01:00
|
|
|
}
|
2022-03-11 13:43:17 +01:00
|
|
|
// Now we add the list of events to likwid
|
|
|
|
cstr = C.CString(estr)
|
|
|
|
gid = C.perfmon_addEventSet(cstr)
|
|
|
|
} else {
|
|
|
|
cclog.ComponentError(m.name, "Invalid Likwid eventset config, no events given")
|
|
|
|
continue
|
2022-02-01 16:01:31 +01:00
|
|
|
}
|
2021-11-25 15:11:39 +01:00
|
|
|
if gid >= 0 {
|
|
|
|
m.groups = append(m.groups, gid)
|
|
|
|
}
|
|
|
|
C.free(unsafe.Pointer(cstr))
|
|
|
|
m.results[i] = make(map[int]map[string]interface{})
|
|
|
|
m.mresults[i] = make(map[int]map[string]float64)
|
2022-01-21 15:20:53 +01:00
|
|
|
for tid := range m.cpulist {
|
2021-11-25 15:11:39 +01:00
|
|
|
m.results[i][tid] = make(map[string]interface{})
|
|
|
|
m.mresults[i][tid] = make(map[string]float64)
|
2022-02-02 14:52:07 +01:00
|
|
|
if i == 0 {
|
|
|
|
m.gmresults[tid] = make(map[string]float64)
|
|
|
|
}
|
2021-11-25 15:11:39 +01:00
|
|
|
}
|
2021-03-25 17:47:08 +01:00
|
|
|
}
|
2022-02-01 16:01:31 +01:00
|
|
|
for _, metric := range m.config.Metrics {
|
2022-02-02 14:52:07 +01:00
|
|
|
// Try to evaluate the global metric
|
2022-02-03 16:52:55 +01:00
|
|
|
_, err := agg.EvalFloat64Condition(metric.Calc, globalParams)
|
2022-02-01 16:01:31 +01:00
|
|
|
if err != nil {
|
|
|
|
cclog.ComponentError(m.name, "Calculation for metric", metric.Name, "failed:", err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
2021-11-25 14:04:03 +01:00
|
|
|
|
2022-02-02 14:52:07 +01:00
|
|
|
// If no event set could be added, shut down LikwidCollector
|
2021-05-18 15:14:11 +02:00
|
|
|
if len(m.groups) == 0 {
|
|
|
|
C.perfmon_finalize()
|
|
|
|
C.topology_finalize()
|
2022-02-01 16:01:31 +01:00
|
|
|
err := errors.New("no LIKWID performance group initialized")
|
|
|
|
cclog.ComponentError(m.name, err.Error())
|
|
|
|
return err
|
2021-05-18 15:14:11 +02:00
|
|
|
}
|
2021-11-25 14:04:03 +01:00
|
|
|
m.basefreq = getBaseFreq()
|
2022-02-08 13:39:58 +01:00
|
|
|
cclog.ComponentDebug(m.name, "BaseFreq", m.basefreq)
|
2021-05-18 15:14:11 +02:00
|
|
|
m.init = true
|
2021-05-14 19:21:16 +02:00
|
|
|
return nil
|
2021-03-25 14:47:10 +01:00
|
|
|
}
|
|
|
|
|
2022-02-02 14:52:07 +01:00
|
|
|
// take a measurement for 'interval' seconds of event set index 'group'
|
2022-02-01 16:01:31 +01:00
|
|
|
func (m *LikwidCollector) takeMeasurement(group int, interval time.Duration) error {
|
2021-11-25 14:04:03 +01:00
|
|
|
var ret C.int
|
2022-02-01 16:01:31 +01:00
|
|
|
gid := m.groups[group]
|
|
|
|
ret = C.perfmon_setupCounters(gid)
|
|
|
|
if ret != 0 {
|
|
|
|
gctr := C.GoString(C.perfmon_getGroupName(gid))
|
2022-02-21 13:29:33 +01:00
|
|
|
err := fmt.Errorf("failed to setup performance group %d (%s)", gid, gctr)
|
2022-02-01 16:01:31 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
ret = C.perfmon_startCounters()
|
|
|
|
if ret != 0 {
|
|
|
|
gctr := C.GoString(C.perfmon_getGroupName(gid))
|
2022-02-21 13:29:33 +01:00
|
|
|
err := fmt.Errorf("failed to start performance group %d (%s)", gid, gctr)
|
2022-02-01 16:01:31 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.running = true
|
|
|
|
time.Sleep(interval)
|
|
|
|
m.running = false
|
|
|
|
ret = C.perfmon_stopCounters()
|
|
|
|
if ret != 0 {
|
|
|
|
gctr := C.GoString(C.perfmon_getGroupName(gid))
|
2022-02-21 13:29:33 +01:00
|
|
|
err := fmt.Errorf("failed to stop performance group %d (%s)", gid, gctr)
|
2022-02-01 16:01:31 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2021-11-25 15:11:39 +01:00
|
|
|
|
2022-02-02 14:52:07 +01:00
|
|
|
// Get all measurement results for an event set, derive the metric values out of the measurement results and send it
|
|
|
|
func (m *LikwidCollector) calcEventsetMetrics(group int, interval time.Duration, output chan lp.CCMetric) error {
|
2022-02-01 16:01:31 +01:00
|
|
|
var eidx C.int
|
|
|
|
evset := m.config.Eventsets[group]
|
|
|
|
gid := m.groups[group]
|
2022-02-08 13:39:58 +01:00
|
|
|
invClock := float64(1.0 / m.basefreq)
|
2022-02-02 14:52:07 +01:00
|
|
|
|
|
|
|
// Go over events and get the results
|
|
|
|
for eidx = 0; int(eidx) < len(evset.Events); eidx++ {
|
|
|
|
ctr := C.perfmon_getCounterName(gid, eidx)
|
|
|
|
gctr := C.GoString(ctr)
|
2022-03-11 13:43:17 +01:00
|
|
|
|
|
|
|
for _, tid := range m.cpu2tid {
|
2022-02-02 14:52:07 +01:00
|
|
|
if tid >= 0 {
|
|
|
|
m.results[group][tid]["time"] = interval.Seconds()
|
2022-02-08 13:39:58 +01:00
|
|
|
m.results[group][tid]["inverseClock"] = invClock
|
2022-02-02 14:52:07 +01:00
|
|
|
res := C.perfmon_getLastResult(gid, eidx, C.int(tid))
|
|
|
|
m.results[group][tid][gctr] = float64(res)
|
2021-11-25 15:11:39 +01:00
|
|
|
}
|
2022-02-01 16:01:31 +01:00
|
|
|
}
|
2022-02-02 14:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Go over the event set metrics, derive the value out of the event:counter values and send it
|
|
|
|
for _, metric := range evset.Metrics {
|
|
|
|
// The metric scope is determined in the Init() function
|
|
|
|
// Get the map scope-id -> tids
|
2022-03-11 13:43:17 +01:00
|
|
|
scopemap := m.cpu2tid
|
|
|
|
if metric.Type == "socket" {
|
|
|
|
scopemap = m.sock2tid
|
|
|
|
}
|
2022-02-02 14:52:07 +01:00
|
|
|
for domain, tid := range scopemap {
|
|
|
|
if tid >= 0 {
|
2022-02-03 16:52:55 +01:00
|
|
|
value, err := agg.EvalFloat64Condition(metric.Calc, m.results[group][tid])
|
2022-02-02 14:52:07 +01:00
|
|
|
if err != nil {
|
|
|
|
cclog.ComponentError(m.name, "Calculation for metric", metric.Name, "failed:", err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
m.mresults[group][tid][metric.Name] = value
|
2022-02-21 13:29:33 +01:00
|
|
|
if m.config.InvalidToZero && math.IsNaN(value) {
|
|
|
|
value = 0.0
|
|
|
|
}
|
|
|
|
if m.config.InvalidToZero && math.IsInf(value, 0) {
|
2022-02-07 18:35:08 +01:00
|
|
|
value = 0.0
|
|
|
|
}
|
2022-02-02 14:52:07 +01:00
|
|
|
// Now we have the result, send it with the proper tags
|
2022-02-08 13:39:58 +01:00
|
|
|
if !math.IsNaN(value) {
|
|
|
|
if metric.Publish {
|
|
|
|
fields := map[string]interface{}{"value": value}
|
2022-03-11 13:43:17 +01:00
|
|
|
y, err := lp.New(metric.Name, map[string]string{"type": metric.Type}, m.meta, fields, time.Now())
|
2022-02-08 13:39:58 +01:00
|
|
|
if err == nil {
|
2022-03-11 13:43:17 +01:00
|
|
|
if metric.Type != "node" {
|
|
|
|
y.AddTag("type-id", fmt.Sprintf("%d", domain))
|
|
|
|
}
|
|
|
|
if len(metric.Unit) > 0 {
|
|
|
|
y.AddMeta("unit", metric.Unit)
|
|
|
|
}
|
2022-02-08 13:39:58 +01:00
|
|
|
output <- y
|
|
|
|
}
|
2022-02-07 17:41:35 +01:00
|
|
|
}
|
2022-02-02 14:52:07 +01:00
|
|
|
}
|
2021-11-25 15:11:39 +01:00
|
|
|
}
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-02 14:52:07 +01:00
|
|
|
|
2022-02-01 16:01:31 +01:00
|
|
|
return nil
|
|
|
|
}
|
2021-11-25 15:11:39 +01:00
|
|
|
|
2022-02-02 14:52:07 +01:00
|
|
|
// Go over the global metrics, derive the value out of the event sets' metric values and send it
|
|
|
|
func (m *LikwidCollector) calcGlobalMetrics(interval time.Duration, output chan lp.CCMetric) error {
|
2021-11-25 14:04:03 +01:00
|
|
|
for _, metric := range m.config.Metrics {
|
2022-03-11 13:43:17 +01:00
|
|
|
scopemap := m.cpu2tid
|
|
|
|
if metric.Type == "socket" {
|
|
|
|
scopemap = m.sock2tid
|
|
|
|
}
|
2022-02-02 14:52:07 +01:00
|
|
|
for domain, tid := range scopemap {
|
|
|
|
if tid >= 0 {
|
|
|
|
// Here we generate parameter list
|
|
|
|
params := make(map[string]interface{})
|
|
|
|
for j := range m.groups {
|
|
|
|
for mname, mres := range m.mresults[j][tid] {
|
|
|
|
params[mname] = mres
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Evaluate the metric
|
2022-02-03 16:52:55 +01:00
|
|
|
value, err := agg.EvalFloat64Condition(metric.Calc, params)
|
2022-02-02 14:52:07 +01:00
|
|
|
if err != nil {
|
|
|
|
cclog.ComponentError(m.name, "Calculation for metric", metric.Name, "failed:", err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
m.gmresults[tid][metric.Name] = value
|
2022-02-21 13:29:33 +01:00
|
|
|
if m.config.InvalidToZero && math.IsNaN(value) {
|
|
|
|
value = 0.0
|
|
|
|
}
|
|
|
|
if m.config.InvalidToZero && math.IsInf(value, 0) {
|
2022-02-07 18:35:08 +01:00
|
|
|
value = 0.0
|
|
|
|
}
|
2022-02-02 14:52:07 +01:00
|
|
|
// Now we have the result, send it with the proper tags
|
2022-02-08 13:39:58 +01:00
|
|
|
if !math.IsNaN(value) {
|
|
|
|
if metric.Publish {
|
2022-03-11 13:43:17 +01:00
|
|
|
tags := map[string]string{"type": metric.Type}
|
2022-02-08 13:39:58 +01:00
|
|
|
fields := map[string]interface{}{"value": value}
|
|
|
|
y, err := lp.New(metric.Name, tags, m.meta, fields, time.Now())
|
|
|
|
if err == nil {
|
2022-03-11 13:43:17 +01:00
|
|
|
if metric.Type != "node" {
|
|
|
|
y.AddTag("type-id", fmt.Sprintf("%d", domain))
|
|
|
|
}
|
|
|
|
if len(metric.Unit) > 0 {
|
|
|
|
y.AddMeta("unit", metric.Unit)
|
|
|
|
}
|
2022-02-08 13:39:58 +01:00
|
|
|
output <- y
|
|
|
|
}
|
2022-02-07 17:41:35 +01:00
|
|
|
}
|
2021-11-25 15:11:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
2022-02-01 16:01:31 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-02-02 14:52:07 +01:00
|
|
|
// main read function taking multiple measurement rounds, each 'interval' seconds long
|
2022-02-01 16:01:31 +01:00
|
|
|
func (m *LikwidCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|
|
|
if !m.init {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-02-02 16:55:15 +01:00
|
|
|
for i := range m.groups {
|
2022-02-01 16:01:31 +01:00
|
|
|
// measure event set 'i' for 'interval' seconds
|
|
|
|
err := m.takeMeasurement(i, interval)
|
|
|
|
if err != nil {
|
|
|
|
cclog.ComponentError(m.name, err.Error())
|
2022-02-21 13:29:33 +01:00
|
|
|
return
|
2022-02-01 16:01:31 +01:00
|
|
|
}
|
2022-02-02 14:52:07 +01:00
|
|
|
// read measurements and derive event set metrics
|
|
|
|
m.calcEventsetMetrics(i, interval, output)
|
2021-11-25 15:11:39 +01:00
|
|
|
}
|
2022-02-02 14:52:07 +01:00
|
|
|
// use the event set metrics to derive the global metrics
|
|
|
|
m.calcGlobalMetrics(interval, output)
|
2021-03-25 14:47:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *LikwidCollector) Close() {
|
2021-05-18 15:14:11 +02:00
|
|
|
if m.init {
|
2022-02-01 16:01:31 +01:00
|
|
|
cclog.ComponentDebug(m.name, "Closing ...")
|
2021-11-25 15:11:39 +01:00
|
|
|
m.init = false
|
2022-02-01 16:01:31 +01:00
|
|
|
if m.running {
|
|
|
|
cclog.ComponentDebug(m.name, "Stopping counters")
|
|
|
|
C.perfmon_stopCounters()
|
|
|
|
}
|
|
|
|
cclog.ComponentDebug(m.name, "Finalize LIKWID perfmon module")
|
2021-05-18 15:14:11 +02:00
|
|
|
C.perfmon_finalize()
|
2022-02-01 16:01:31 +01:00
|
|
|
cclog.ComponentDebug(m.name, "Finalize LIKWID topology module")
|
2021-05-18 15:14:11 +02:00
|
|
|
C.topology_finalize()
|
2022-02-01 16:01:31 +01:00
|
|
|
cclog.ComponentDebug(m.name, "Closing done")
|
2021-05-18 15:14:11 +02:00
|
|
|
}
|
2021-03-25 14:47:10 +01:00
|
|
|
}
|