From 8b373cc2c0ef21c095f0eb2ec045bec2fe35469f Mon Sep 17 00:00:00 2001 From: Michael Schwarz Date: Mon, 22 Jun 2026 15:12:36 +0200 Subject: [PATCH] Add filter for ipmi metrics --- collectors/ipmiMetric.go | 24 ++++++++++++++++++++++++ collectors/ipmiMetric.md | 5 ++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/collectors/ipmiMetric.go b/collectors/ipmiMetric.go index 3740f4c..c3f9512 100644 --- a/collectors/ipmiMetric.go +++ b/collectors/ipmiMetric.go @@ -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) diff --git a/collectors/ipmiMetric.md b/collectors/ipmiMetric.md index c1269f2..349c416 100644 --- a/collectors/ipmiMetric.md +++ b/collectors/ipmiMetric.md @@ -15,7 +15,8 @@ hugo_path: docs/reference/cc-metric-collector/collectors/ipmi.md "ipmistat": { "ipmitool_path": "/path/to/ipmitool", "ipmisensors_path": "/path/to/ipmi-sensors", - "use_sudo": true + "use_sudo": true, + "include_metrics" : [] } ``` @@ -36,3 +37,5 @@ Defaults: monitoring !log_allowed, !pam_session monitoring ALL = (root) NOPASSWD:/usr/bin/ipmitool sensor monitoring ALL = (root) NOPASSWD:/usr/sbin/ipmi-sensors --comma-separated-output --sdr-cache-recreate ``` + +If `include_ipmi_metrics` contains any entry, ipmistat collector will only submit these metrics. Any other values will get discarded. \ No newline at end of file