Compare commits

..

1 Commits

Author SHA1 Message Date
Thomas Roehl
b3eb0679b9 Fix max clock metrics 2025-10-20 16:58:39 +02:00

View File

@@ -20,17 +20,18 @@ import (
lp "github.com/ClusterCockpit/cc-lib/ccMessage"
)
// Konstante für den Pfad zu /proc/diskstats
const IOSTATFILE = `/proc/diskstats`
type IOstatCollectorConfig struct {
ExcludeMetrics []string `json:"exclude_metrics,omitempty"`
// Neues Feld zum Ausschließen von Devices per JSON-Konfiguration
ExcludeDevices []string `json:"exclude_devices,omitempty"`
}
type IOstatCollectorEntry struct {
currentValues map[string]int64
lastValues map[string]int64
tags map[string]string
lastValues map[string]int64
tags map[string]string
}
type IOstatCollector struct {
@@ -104,27 +105,16 @@ func (m *IOstatCollector) Init(config json.RawMessage) error {
if _, skip := stringArrayContains(m.config.ExcludeDevices, device); skip {
continue
}
currentValues := make(map[string]int64)
lastValues := make(map[string]int64)
values := make(map[string]int64)
for m := range m.matches {
currentValues[m] = 0
lastValues[m] = 0
}
for name, idx := range m.matches {
if idx < len(linefields) {
if value, err := strconv.ParseInt(linefields[idx], 0, 64); err == nil {
currentValues[name] = value
lastValues[name] = value // Set last to current for first read
}
}
values[m] = 0
}
m.devices[device] = IOstatCollectorEntry{
tags: map[string]string{
"device": device,
"type": "node",
},
currentValues: currentValues,
lastValues: lastValues,
lastValues: values,
}
}
m.init = true
@@ -163,22 +153,18 @@ func (m *IOstatCollector) Read(interval time.Duration, output chan lp.CCMessage)
if _, ok := m.devices[device]; !ok {
continue
}
// Update current and last values
entry := m.devices[device]
for name, idx := range m.matches {
if idx < len(linefields) {
x, err := strconv.ParseInt(linefields[idx], 0, 64)
if err == nil {
// Calculate difference using previous current and new value
diff := x - entry.currentValues[name]
y, err := lp.NewMetric(name, entry.tags, m.meta, int(diff), time.Now())
diff := x - entry.lastValues[name]
y, err := lp.NewMessage(name, entry.tags, m.meta, map[string]interface{}{"value": int(diff)}, time.Now())
if err == nil {
output <- y
}
// Update last to previous current, and current to new value
entry.lastValues[name] = entry.currentValues[name]
entry.currentValues[name] = x
}
entry.lastValues[name] = x
}
}
m.devices[device] = entry