Numastats: Read in config and send abs values by default. Fixes #146 (#147)

This commit is contained in:
Thomas Gruber 2025-06-17 10:32:08 +02:00
parent 4c7a0e064f
commit b9665d0d68

View File

@ -1,10 +1,3 @@
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
// All rights reserved. This file is part of cc-lib.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// additional authors:
// Holger Obermaier (NHR@KIT)
package collectors
import (
@ -85,6 +78,14 @@ func (m *NUMAStatsCollector) Init(config json.RawMessage) error {
"group": "NUMA",
}
m.config.SendAbsoluteValues = true
if len(config) > 0 {
err := json.Unmarshal(config, &m.config)
if err != nil {
return fmt.Errorf("unable to unmarshal numastat configuration: %s", err.Error())
}
}
// Loop for all NUMA node directories
base := "/sys/devices/system/node/node"
globPattern := base + "[0-9]*"
@ -152,11 +153,11 @@ func (m *NUMAStatsCollector) Read(interval time.Duration, output chan lp.CCMessa
}
if m.config.SendAbsoluteValues {
msg, err := lp.NewMessage(
msg, err := lp.NewMetric(
"numastats_"+key,
t.tagSet,
m.meta,
map[string]interface{}{"value": value},
value,
now,
)
if err == nil {
@ -168,11 +169,11 @@ func (m *NUMAStatsCollector) Read(interval time.Duration, output chan lp.CCMessa
prev, ok := t.previousValues[key]
if ok {
rate := float64(value-prev) / timeDiff
msg, err := lp.NewMessage(
msg, err := lp.NewMetric(
"numastats_"+key+"_rate",
t.tagSet,
m.meta,
map[string]interface{}{"value": rate},
rate,
now,
)
if err == nil {