mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2026-02-13 14:41:45 +01:00
Use slices to exclude metrics
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -43,8 +44,13 @@ func (m *CpustatCollector) Init(config json.RawMessage) error {
|
|||||||
return fmt.Errorf("%s Init(): setup() call failed: %w", m.name, err)
|
return fmt.Errorf("%s Init(): setup() call failed: %w", m.name, err)
|
||||||
}
|
}
|
||||||
m.parallel = true
|
m.parallel = true
|
||||||
m.meta = map[string]string{"source": m.name, "group": "CPU"}
|
m.meta = map[string]string{
|
||||||
m.nodetags = map[string]string{"type": "node"}
|
"source": m.name,
|
||||||
|
"group": "CPU",
|
||||||
|
}
|
||||||
|
m.nodetags = map[string]string{
|
||||||
|
"type": "node",
|
||||||
|
}
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err := json.Unmarshal(config, &m.config)
|
err := json.Unmarshal(config, &m.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -66,14 +72,7 @@ func (m *CpustatCollector) Init(config json.RawMessage) error {
|
|||||||
|
|
||||||
m.matches = make(map[string]int)
|
m.matches = make(map[string]int)
|
||||||
for match, index := range matches {
|
for match, index := range matches {
|
||||||
doExclude := false
|
if !slices.Contains(m.config.ExcludeMetrics, match) {
|
||||||
for _, exclude := range m.config.ExcludeMetrics {
|
|
||||||
if match == exclude {
|
|
||||||
doExclude = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !doExclude {
|
|
||||||
m.matches[match] = index
|
m.matches[match] = index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user