From 704fd5250351e3bfce27cab492acf4a14716e1d7 Mon Sep 17 00:00:00 2001 From: ibrahimkk-moideen Date: Wed, 24 Apr 2024 16:39:49 -0400 Subject: [PATCH] fix hostname label in device_info --- exporter/exporter.go | 19 ++++++++++--------- exporter/exporter_test.go | 3 ++- exporter/handlers.go | 2 +- oem/system.go | 10 +++++----- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/exporter/exporter.go b/exporter/exporter.go index 02367b4..2952090 100644 --- a/exporter/exporter.go +++ b/exporter/exporter.go @@ -79,15 +79,15 @@ var ( // Exporter collects chassis manager stats from the given URI and exports them using // the prometheus metrics package. type Exporter struct { - ctx context.Context - mutex sync.RWMutex - pool *pool.Pool - client *retryablehttp.Client - host string - url string - credProfile string - biosVersion string - + ctx context.Context + mutex sync.RWMutex + pool *pool.Pool + client *retryablehttp.Client + host string + url string + credProfile string + biosVersion string + systemHostname string ChassisSerialNumber string DeviceMetrics *map[string]*metrics Model string @@ -255,6 +255,7 @@ func NewExporter(ctx context.Context, target, uri, profile, model string, exclud } exp.biosVersion = sysResp.BiosVersion exp.ChassisSerialNumber = sysResp.SerialNumber + exp.systemHostname = sysResp.SystemHostname // call /redfish/v1/Systems/XXXXX/ for memory summary and smart storage batteries // TODO: do not assume 1 systems endpoint diff --git a/exporter/exporter_test.go b/exporter/exporter_test.go index d7c2234..5dcfb49 100644 --- a/exporter/exporter_test.go +++ b/exporter/exporter_test.go @@ -38,7 +38,7 @@ const ( GoodDeviceInfoExpected = ` # HELP redfish_device_info Current snapshot of device firmware information # TYPE redfish_device_info gauge - redfish_device_info{biosVersion="U99 v0.00 (xx/xx/xxxx)",chassisModel="model a",chassisSerialNumber="SN98765",firmwareVersion="iLO 5 v2.65",name="test description"} 1 + redfish_device_info{biosVersion="U99 v0.00 (xx/xx/xxxx)",chassisModel="model a",chassisSerialNumber="SN98765",firmwareVersion="iLO 5 v2.65",name="hostname123"} 1 ` GoodCPUStatusExpected = ` # HELP redfish_cpu_status Current cpu status 1 = OK, 0 = BAD @@ -1110,6 +1110,7 @@ func Test_Exporter_Metrics_Handling(t *testing.T) { host: "fishymetrics.com", Model: "model a", biosVersion: "U99 v0.00 (xx/xx/xxxx)", + systemHostname: "hostname123", ChassisSerialNumber: "SN98765", DeviceMetrics: NewDeviceMetrics(), } diff --git a/exporter/handlers.go b/exporter/handlers.go index 0fef0c7..36cff69 100644 --- a/exporter/handlers.go +++ b/exporter/handlers.go @@ -71,7 +71,7 @@ func (e *Exporter) exportFirmwareMetrics(body []byte) error { return fmt.Errorf("Error Unmarshalling FirmwareMetrics - " + err.Error()) } - (*dm)["deviceInfo"].WithLabelValues(mgr.Description, e.ChassisSerialNumber, e.Model, mgr.FirmwareVersion, e.biosVersion).Set(1.0) + (*dm)["deviceInfo"].WithLabelValues(e.systemHostname, e.ChassisSerialNumber, e.Model, mgr.FirmwareVersion, e.biosVersion).Set(1.0) return nil } diff --git a/oem/system.go b/oem/system.go index 2577847..dc4207b 100644 --- a/oem/system.go +++ b/oem/system.go @@ -21,11 +21,11 @@ package oem // ServerManager contains the BIOS version and Serial number of the chassis, // we will also collect memory summary and storage battery metrics if present type System struct { - BiosVersion string `json:"BiosVersion"` - SerialNumber string `json:"SerialNumber"` - IloServerName string `json:"HostName"` - Oem OemSys `json:"Oem"` - MemorySummary MemorySummary `json:"MemorySummary"` + BiosVersion string `json:"BiosVersion"` + SerialNumber string `json:"SerialNumber"` + SystemHostname string `json:"HostName"` + Oem OemSys `json:"Oem"` + MemorySummary MemorySummary `json:"MemorySummary"` } type OemSys struct {