Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bd4ee6d
Add integration test which simply creates a collector and scrapes it …
MurrayGroves Oct 22, 2026
b31b6d3
Move collectors into sub-packages
MurrayGroves Oct 23, 2026
83f0ac2
Split thermal collector into sub-package, test it against DSP2043
MurrayGroves Oct 26, 2026
7ee9416
Split power collector into sub-package, test it against DSP2043 1.0.0…
MurrayGroves Oct 26, 2026
4a72415
Split network collector into sub-package, add support for new Port type
MurrayGroves Oct 26, 2026
17e76b1
Tidy up chassis collector
MurrayGroves Oct 26, 2026
2595cb5
Tidy up manager collector
MurrayGroves Oct 26, 2026
7285272
Split system/memory into new collector
MurrayGroves Oct 26, 2026
6641321
Split system/processors into new collector
MurrayGroves Oct 26, 2026
12fdd69
Split system/pcie_devices into new collector
MurrayGroves Oct 27, 2026
2f092c4
Split system/network_interfaces into new collector
MurrayGroves Oct 27, 2026
a13f690
Split system/ethernet_interfaces into new collector
MurrayGroves Oct 27, 2026
2b1eab5
Split system/pcie_functions into new collector
MurrayGroves Oct 27, 2026
fe01ddc
Move system/logs into separate function
MurrayGroves Oct 27, 2026
f9ca0ad
Allow concurrent requests, re-using TCP connections, fix unguarded po…
MurrayGroves Oct 27, 2026
9f5d896
Split system/storage into new collector
MurrayGroves Oct 27, 2026
95159ba
Split system/simple_storage into new collector
MurrayGroves Oct 27, 2026
7cfc5de
Tidy up system collector
MurrayGroves Oct 27, 2026
5b81f17
Split power into deprecated power, new power subsystem
MurrayGroves Oct 27, 2026
3805586
Add support for ThermalSubsystem
MurrayGroves Oct 27, 2026
a5b6fa7
Use pedantic registry, properly describe sub-collectors
MurrayGroves Oct 28, 2026
27c6054
Test manager collector
MurrayGroves Oct 28, 2026
b229acd
Remove un-used mockup examples
MurrayGroves Oct 28, 2026
1b57b4a
Test chassis collector
MurrayGroves Oct 28, 2026
3fe1bb4
Remove un-used test parameter
MurrayGroves Oct 28, 2026
074ddee
Test system collector
MurrayGroves Oct 28, 2026
1155935
Tidy up logging
MurrayGroves Oct 28, 2026
bd91063
Fix style issues
MurrayGroves Oct 28, 2026
16c56ee
Use development version of gofish
MurrayGroves Oct 28, 2026
ccd4a17
Run tests in CI
MurrayGroves Oct 28, 2026
878da26
Bump setup-go, point at go.mod
MurrayGroves Oct 29, 2026
2a909cb
Remove web profiler
MurrayGroves Oct 29, 2026
1194f45
Test via makefile
MurrayGroves Oct 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
7 changes: 5 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v7
with:
go-version: '1.27'
go-version-file: 'go.mod'

- name: Check style
run: make style

- name: Run tests
run: make test

- name: Build Docker container
run: make docker-build
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ config.yml

# IDE files
.vscode
.zed

# Commit all Helm chart files
!helm/**
helm/*.lock
helm/*.lock

redfish_exporter_cpu_profile
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ BRANCH ?=$(shell git rev-parse --abbrev-ref HEAD)
TIME ?=$(shell date --rfc-3339=seconds)
DOCKER := $(shell { command -v podman || command -v docker; } 2>/dev/null)

all: fmt style build docker-build
all: fmt style build test docker-build

style:
@echo ">> checking code style"
Expand All @@ -33,6 +33,10 @@ build: |
@echo ">> building binaries"
$(GO) build -o build/redfish_exporter -ldflags '-X "main.Version=$(VERSION)" -X "main.BuildRevision=$(REVISION)" -X "main.BuildBranch=$(BRANCH)" -X "main.BuildTime=$(TIME)"'

test: |
@echo ">> testing"
FIXTURES_DIR="$(shell pwd)/test_dependencies" $(GO) test -race ./...

docker-build:
$(DOCKER) build -t stackhpc/redfish_exporter --network=host .

Expand Down
189 changes: 189 additions & 0 deletions collector/chassis/collector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
package chassis

import (
"bytes"
"fmt"
"log/slog"
"sync"

"github.com/prometheus/client_golang/prometheus"
"github.com/stmcginnis/gofish/schemas"

"github.com/stackhpc/redfish_exporter/collector/chassis/network_adapters"
"github.com/stackhpc/redfish_exporter/collector/chassis/power"
"github.com/stackhpc/redfish_exporter/collector/chassis/power_subsystem"
"github.com/stackhpc/redfish_exporter/collector/chassis/thermal"
"github.com/stackhpc/redfish_exporter/collector/chassis/thermal_subsystem"
"github.com/stackhpc/redfish_exporter/common"
)

// ChassisSubsystem is the chassis subsystem
var (
ChassisSubsystem = "chassis"
ChassisLabelNames = []string{"resource", "chassis_id"}
ChassisModel = []string{"resource", "chassis_id", "manufacturer", "model", "part_number", "sku"}
ChassisPhysicalSecurityLabelNames = []string{"resource", "chassis_id", "intrusion_sensor_number", "intrusion_sensor_rearm"}

ChassisLogServiceLabelNames = []string{"chassis_id", "log_service", "log_service_id", "log_service_enabled", "log_service_overwrite_policy"}
ChassisLogEntryLabelNames = []string{"chassis_id", "log_service", "log_service_id", "log_entry", "log_entry_id", "log_entry_code", "log_entry_type", "log_entry_message_id", "log_entry_sensor_number", "log_entry_sensor_type"}

metricMap = createMetricMap()
)

func createMetricMap() map[string]common.Metric {
metrics := make(map[string]common.Metric)
common.AddToMetricMap(metrics, ChassisSubsystem, "health", fmt.Sprintf("health of chassis,%s", common.HealthHelp), ChassisLabelNames)
common.AddToMetricMap(metrics, ChassisSubsystem, "state", fmt.Sprintf("state of chassis,%s", common.StateHelp), ChassisLabelNames)
common.AddToMetricMap(metrics, ChassisSubsystem, "model_info", "organization responsible for producing the chassis, the name by which the manufacturer generally refers to the chassis, and a part number and sku assigned by the organization that is responsible for producing or manufacturing the chassis", ChassisModel)

common.AddToMetricMap(metrics, ChassisSubsystem, "physical_security_sensor_state", fmt.Sprintf("indicates the known state of the physical security sensor, such as if it is hardware intrusion detected,%s", common.IntrusionSensorHelp), ChassisPhysicalSecurityLabelNames)

common.AddToMetricMap(metrics, ChassisSubsystem, "log_service_state", fmt.Sprintf("chassis log service state,%s", common.StateHelp), ChassisLogServiceLabelNames)
common.AddToMetricMap(metrics, ChassisSubsystem, "log_service_health_state", fmt.Sprintf("chassis log service health state,%s", common.HealthHelp), ChassisLogServiceLabelNames)
common.AddToMetricMap(metrics, ChassisSubsystem, "log_entry_severity_state", fmt.Sprintf("chassis log entry severity state,%s", common.SeverityHelp), ChassisLogEntryLabelNames)

return metrics
}

// Collector implements the prometheus.Collector.
type Collector struct {
Ctx *common.CollectionContext
collectorScrapeStatus *prometheus.GaugeVec
Log *slog.Logger
thermal *thermal.Collector
}

// NewCollector returns a collector that collecting chassis statistics
func NewCollector(ctx *common.CollectionContext, logger *slog.Logger) *Collector {
// get service from redfish client

return &Collector{
Ctx: ctx,
Log: logger.With(
"collector", "ChassisCollector",
),
collectorScrapeStatus: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: common.Namespace,
Name: "collector_scrape_status",
Help: "collector_scrape_status",
},
[]string{"collector"},
),
}
}

// Describe implemented prometheus.Collector
func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
for _, metric := range metricMap {
ch <- metric.Desc
}
c.collectorScrapeStatus.Describe(ch)
network_adapters.Describe(ch)
power.Describe(ch)
power_subsystem.Describe(ch)
thermal.Describe(ch)
thermal_subsystem.Describe(ch)
}

// Collect implemented prometheus.Collector
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
service := c.Ctx.RedfishClient.Service

wg := &sync.WaitGroup{}

// get a list of chassis from service
chassises, err := service.Chassis()
if err != nil {
c.Log.Error("error getting chassis from service", "operation", "service.Chassis()", "err", err)
return
}

// process the chassises
for _, chassis := range chassises {
chassisLogContext := c.Log.With("chassis", chassis.ID)
chassisLogContext.Info("collector scrape started")
ChassisLabelValues := []string{"chassis", chassis.ID}
if chassisStatusHealthValue, ok := common.ParseCommonStatusHealth(chassis.Status.Health); ok {
ch <- prometheus.MustNewConstMetric(metricMap["chassis_health"].Desc, prometheus.GaugeValue, chassisStatusHealthValue, ChassisLabelValues...)
}
if chassisStatusStateValue, ok := common.ParseCommonStatusState(chassis.Status.State); ok {
ch <- prometheus.MustNewConstMetric(metricMap["chassis_state"].Desc, prometheus.GaugeValue, chassisStatusStateValue, ChassisLabelValues...)
}

ChassisModelLabelValues := []string{"chassis", chassis.ID, chassis.Manufacturer, chassis.Model, chassis.PartNumber, chassis.SKU}
ch <- prometheus.MustNewConstMetric(metricMap["chassis_model_info"].Desc, prometheus.GaugeValue, 1, ChassisModelLabelValues...)

physicalSecurity := chassis.PhysicalSecurity
if physicalSecurity != (schemas.PhysicalSecurity{}) {
physicalSecurityIntrusionSensor := physicalSecurity.IntrusionSensor
physicalSecurityIntrusionSensorNumber := fmt.Sprint(physicalSecurity.IntrusionSensorNumber)
physicalSecurityIntrusionSensorReArmMethod := string(physicalSecurity.IntrusionSensorReArm)

if phySecIntrusionSensor, ok := parsePhySecIntrusionSensor(physicalSecurityIntrusionSensor); ok {
ChassisPhysicalSecurityLabelValues := []string{"physical_security", chassis.ID, physicalSecurityIntrusionSensorNumber, physicalSecurityIntrusionSensorReArmMethod}
ch <- prometheus.MustNewConstMetric(metricMap["chassis_physical_security_sensor_state"].Desc, prometheus.GaugeValue, phySecIntrusionSensor, ChassisPhysicalSecurityLabelValues...)
}
}

thermal := thermal.NewCollector(c.Ctx, chassisLogContext, chassis)
wg.Go(func() { thermal.Collect(ch) })

// Power() was deprecated in Redfish v1.15.0
power := power.NewCollector(c.Ctx, chassisLogContext, chassis)
wg.Go(func() { power.Collect(ch) })

// It was replaced with PowerSubsystem()
power_subsystem := power_subsystem.NewCollector(c.Ctx, chassisLogContext, chassis)
wg.Go(func() { power_subsystem.Collect(ch) })

network_adapters := network_adapters.NewCollector(c.Ctx, chassisLogContext, chassis)
wg.Go(func() { network_adapters.Collect(ch) })

// process log services
if c.Ctx.CollectLogs {
wg.Go(func() { c.collectLogs(ch, chassis) })
}
}

wg.Wait()
c.Log.Info("collector scrape completed")
c.collectorScrapeStatus.WithLabelValues("chassis").Set(float64(1))
}

func (c *Collector) collectLogs(ch chan<- prometheus.Metric, chassis *schemas.Chassis) {
logServices, err := chassis.LogServices()
if err != nil {
c.Log.Error("error getting log services from chassis", "operation", "chassis.LogServices()", "err", err)
return
} else if logServices == nil {
c.Log.Debug("no log services found", "operation", "chassis.LogServices()")
return
}

wg := &sync.WaitGroup{}
for _, logService := range logServices {
wg.Go(func() {
if err = common.ParseLogService(ch, metricMap, c.Ctx, c.Log.With("log_service", logService.ID), ChassisSubsystem, chassis.ID, logService); err != nil {
c.Log.Error("error getting log entries from log service", "operation", "chassis.LogServices()", "err", err)
}
})
}

wg.Wait()
}

func parsePhySecIntrusionSensor(method schemas.IntrusionSensor) (float64, bool) {
if bytes.Equal([]byte(method), []byte("Normal")) {
return float64(1), true

}
if bytes.Equal([]byte(method), []byte("TamperingDetected")) {
return float64(2), true
}
if bytes.Equal([]byte(method), []byte("HardwareIntrusion")) {
return float64(3), true
}

return float64(0), false
}
81 changes: 81 additions & 0 deletions collector/chassis/collector_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package chassis_test

import (
"testing"

"github.com/prometheus/common/promslog"
"github.com/stackhpc/redfish_exporter/collector/chassis"
"github.com/stackhpc/redfish_exporter/common"
redfish_test "github.com/stackhpc/redfish_exporter/common/test"
)

func TestPublicCXL_2026_2(t *testing.T) {
redfishClient := redfish_test.CreateRedfishClient(t, "DSP2043_2026.2/public-cxl")

ctx := common.CollectionContext{
RedfishClient: redfishClient,
CollectLogs: true,
}

promslogConfig := promslog.Config{}
logger := promslog.New(&promslogConfig)

collector := chassis.NewCollector(&ctx, logger)
expected := `
redfish_chassis_log_entry_severity_state{chassis_id="CXL-Chassis",log_entry="Log Entry 1",log_entry_code="",log_entry_id="1",log_entry_message_id="Event.1.0.TempAssert",log_entry_sensor_number="1",log_entry_sensor_type="",log_entry_type="Event",log_service="CXL Module Log Service",log_service_id="LocalLog1"} 3
redfish_chassis_log_service_health_state{chassis_id="CXL-Chassis",log_service="CXL Module Log Service",log_service_enabled="true",log_service_id="LocalLog1",log_service_overwrite_policy="WrapsWhenFull"} 1
redfish_chassis_log_service_state{chassis_id="CXL-Chassis",log_service="CXL Module Log Service",log_service_enabled="true",log_service_id="LocalLog1",log_service_overwrite_policy="WrapsWhenFull"} 1
redfish_chassis_model_info{chassis_id="CXL-Chassis",manufacturer="",model="",part_number="",resource="chassis",sku=""} 1
redfish_chassis_model_info{chassis_id="CXLType1",manufacturer="",model="",part_number="",resource="chassis",sku=""} 1
redfish_chassis_model_info{chassis_id="CXLType2",manufacturer="",model="",part_number="",resource="chassis",sku=""} 1
redfish_chassis_model_info{chassis_id="CXLType3",manufacturer="",model="",part_number="",resource="chassis",sku=""} 1
redfish_chassis_model_info{chassis_id="PooledCXLType1",manufacturer="",model="",part_number="",resource="chassis",sku=""} 1
redfish_chassis_model_info{chassis_id="PooledCXLType2",manufacturer="",model="",part_number="",resource="chassis",sku=""} 1
redfish_chassis_model_info{chassis_id="PooledCXLType3",manufacturer="",model="",part_number="",resource="chassis",sku=""} 1
redfish_chassis_state{chassis_id="CXL-Chassis",resource="chassis"} 1
redfish_chassis_state{chassis_id="CXLType1",resource="chassis"} 1
redfish_chassis_state{chassis_id="CXLType2",resource="chassis"} 1
redfish_chassis_state{chassis_id="CXLType3",resource="chassis"} 1
redfish_chassis_state{chassis_id="PooledCXLType1",resource="chassis"} 1
redfish_chassis_state{chassis_id="PooledCXLType2",resource="chassis"} 1
redfish_chassis_state{chassis_id="PooledCXLType3",resource="chassis"} 1
`
redfish_test.CollectAndCompare(t, collector, expected,
"redfish_chassis_state",
"redfish_chassis_model_info",
// None of the Redfish mockups include physical security sensors
//"redfish_chassis_physical_security_sensor_state",
"redfish_chassis_log_service_state",
"redfish_chassis_log_service_health_state",
"redfish_chassis_log_entry_severity_state",
)
}

func TestPublicCables_2026_2(t *testing.T) {
redfishClient := redfish_test.CreateRedfishClient(t, "DSP2043_2026.2/public-cables")

ctx := common.CollectionContext{
RedfishClient: redfishClient,
CollectLogs: true,
}

promslogConfig := promslog.Config{}
logger := promslog.New(&promslogConfig)

collector := chassis.NewCollector(&ctx, logger)
expected := `
redfish_chassis_health{chassis_id="bmc",resource="chassis"} 1
redfish_chassis_health{chassis_id="hsbp",resource="chassis"} 1
redfish_chassis_model_info{chassis_id="bmc",manufacturer="",model="",part_number="1234567-89",resource="chassis",sku=""} 1
redfish_chassis_model_info{chassis_id="chassis",manufacturer="",model="",part_number="",resource="chassis",sku=""} 1
redfish_chassis_model_info{chassis_id="hsbp",manufacturer="Oogle",model="",part_number="9876543-21",resource="chassis",sku=""} 1
redfish_chassis_state{chassis_id="bmc",resource="chassis"} 3
redfish_chassis_state{chassis_id="chassis",resource="chassis"} 3
redfish_chassis_state{chassis_id="hsbp",resource="chassis"} 3
`
redfish_test.CollectAndCompare(t, collector, expected,
"redfish_chassis_state",
"redfish_chassis_health",
"redfish_chassis_model_info",
)
}
Loading
Loading