Add filter for ipmi metrics

This commit is contained in:
Michael Schwarz
2026-06-22 15:12:36 +02:00
committed by Thomas Gruber
parent f6260a8fb2
commit 8b373cc2c0
2 changed files with 28 additions and 1 deletions
+24
View File
@@ -31,12 +31,26 @@ type IpmiCollector struct {
IpmitoolPath string `json:"ipmitool_path"`
IpmisensorsPath string `json:"ipmisensors_path"`
Sudo bool `json:"use_sudo"`
IncludeMetrics []string `json:"include_metrics"`
}
ipmitool string
ipmisensors string
}
func (m *IpmiCollector) metricIncluded(name string) bool {
if len(m.config.IncludeMetrics) == 0 {
return true
}
for _, metric := range m.config.IncludeMetrics {
if metric == name {
return true
}
}
return false
}
func (m *IpmiCollector) Init(config json.RawMessage) error {
// Check if already initialized
if m.init {
@@ -145,6 +159,11 @@ func (m *IpmiCollector) readIpmiTool(output chan lp.CCMessage) error {
continue
}
name := strings.ToLower(strings.ReplaceAll(strings.TrimSpace(lv[0]), " ", "_"))
if !m.metricIncluded(name) {
continue
}
unit := strings.TrimSpace(lv[2])
switch unit {
case "Volts":
@@ -209,6 +228,11 @@ func (m *IpmiCollector) readIpmiSensors(output chan lp.CCMessage) error {
continue
}
name := strings.ToLower(strings.ReplaceAll(lv[1], " ", "_"))
if !m.metricIncluded(name) {
continue
}
y, err := lp.NewMetric(name, map[string]string{"type": "node"}, m.meta, v, time.Now())
if err != nil {
cclog.ComponentErrorf(m.name, "Failed to create message: %v", err)