Skip to content

Commit

Permalink
fix(metric): Missing health state no longer directly shows warning
Browse files Browse the repository at this point in the history
  • Loading branch information
BirknerAlex committed Mar 28, 2024
1 parent 643324a commit 551eeda
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
6 changes: 6 additions & 0 deletions pkg/drivers/redfish/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"errors"
"fmt"
"net/http"
"os"
"time"

"github.com/g-portal/redfish_exporter/pkg/config"
"github.com/g-portal/redfish_exporter/pkg/drivers/redfish/metrics"
"github.com/prometheus/client_golang/prometheus"
"github.com/stmcginnis/gofish"
Expand Down Expand Up @@ -77,6 +79,10 @@ func (rf *Redfish) Connect(host, username, password string, verifyTLS bool) erro
HTTPClient: httpClient,
}

if verbose := config.GetConfig().Verbose; verbose {
cfg.DumpWriter = os.Stdout
}

rf.client, err = gofish.Connect(cfg)
if err != nil {
return fmt.Errorf("error connecting to redfish: %w", err)
Expand Down
22 changes: 15 additions & 7 deletions pkg/drivers/redfish/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (m *Metrics) Collect() error {
}

for _, system := range systems {
m.WithRedfishHealthMetric(convertHealthStatus(system.Status.Health), map[string]string{
m.WithRedfishHealthMetric(convertHealthStatus(system.Status.Health, false), map[string]string{
"system_id": system.ID,
})

Expand All @@ -48,7 +48,8 @@ func (m *Metrics) Collect() error {

if memory, err := system.Memory(); err == nil {
for _, mem := range memory {
m.WithRedfishMemoryHealthMetric(convertHealthStatus(mem.Status.Health), map[string]string{
m.WithRedfishMemoryHealthMetric(convertHealthStatus(mem.Status.Health,
mem.Status.State == common.EnabledState), map[string]string{
"system_id": system.ID,
"memory_id": mem.ID,
})
Expand All @@ -63,14 +64,16 @@ func (m *Metrics) Collect() error {

if storage, err := system.Storage(); err == nil {
for _, store := range storage {
m.WithRedfishStorageHealthMetric(convertHealthStatus(store.Status.Health), map[string]string{
m.WithRedfishStorageHealthMetric(convertHealthStatus(store.Status.Health,
store.Status.State == common.EnabledState), map[string]string{
"system_id": system.ID,
"storage_id": store.ID,
})

if drives, err := store.Drives(); err == nil {
for _, drive := range drives {
m.WithRedfishDriveHealthMetric(convertHealthStatus(drive.Status.Health), map[string]string{
m.WithRedfishDriveHealthMetric(convertHealthStatus(drive.Status.Health,
drive.FailurePredicted), map[string]string{
"system_id": system.ID,
"storage_id": store.ID,
"drive_id": drive.ID,
Expand All @@ -91,7 +94,8 @@ func (m *Metrics) Collect() error {

if cpus, err := system.Processors(); err == nil {
for _, cpu := range cpus {
m.WithRedfishProcessorHealthMetric(convertHealthStatus(cpu.Status.Health), map[string]string{
m.WithRedfishProcessorHealthMetric(convertHealthStatus(cpu.Status.Health,
cpu.Status.State == common.EnabledState), map[string]string{
"system_id": system.ID,
"processor_id": cpu.ID,
})
Expand All @@ -111,7 +115,7 @@ func (m *Metrics) Collect() error {
return nil
}

func convertHealthStatus(status common.Health) base.RedfishHealthStatus {
func convertHealthStatus(status common.Health, forceWarning bool) base.RedfishHealthStatus {
switch status {
case common.OKHealth:
return base.RedfishHealthOK
Expand All @@ -120,7 +124,11 @@ func convertHealthStatus(status common.Health) base.RedfishHealthStatus {
case common.CriticalHealth:
return base.RedfishHealthCritical
default:
return base.RedfishHealthWarning
if forceWarning {
return base.RedfishHealthWarning
}

return base.RedfishHealthOK
}
}

Expand Down

0 comments on commit 551eeda

Please sign in to comment.