jenningsloy318 / redfish_exporter

exporter to get metrics from redfish based hardware such as lenovo/dell/superc servers
Apache License 2.0
70 stars 62 forks source link

Missing support for power control metrics #12

Closed bluecmd closed 4 years ago

bluecmd commented 4 years ago

Hi,

Supermicro servers export power usage in some models as part of Power Control status.

Something like this might be enough to surface the interesting metrics:

diff --git a/collector/chassis_collector.go b/collector/chassis_collector.go
index 6319cd7..b99aff9 100755
--- a/collector/chassis_collector.go
+++ b/collector/chassis_collector.go
@@ -94,6 +94,14 @@ var (
                                nil,
                        ),
                },
+               "chassis_power_average_consumed_watts": {
+                       desc: prometheus.NewDesc(
+                               prometheus.BuildFQName(namespace, ChassisSubsystem, "power_average_consumed_watts"),
+                               "power wattage watts number of chassis component",
+                               ChassisPowerVotageLabelNames,
+                               nil,
+                       ),
+               },
                "chassis_power_powersupply_state": {
                        desc: prometheus.NewDesc(
                                prometheus.BuildFQName(namespace, ChassisSubsystem, "power_powersupply_state"),
@@ -251,16 +259,22 @@ func (c *ChassisCollector) Collect(ch chan<- prometheus.Metric) {
                                wg3.Add(len(chassisPowerInfoVoltages))
                                for _, chassisPowerInfoVoltage := range chassisPowerInfoVoltages {
                                        go parseChassisPowerInfoVoltage(ch, chassisID, chassisPowerInfoVoltage, wg3)
+                               }

+                               // power control
+                               chassisPowerInfoPowerControls := chassisPowerInfo.PowerControl
+                               wg4 := &sync.WaitGroup{}
+                               wg4.Add(len(chassisPowerInfoPowerControls))
+                               for _, chassisPowerInfoPowerControl := range chassisPowerInfoPowerControls {
+                                       go parseChassisPowerInfoPowerControl(ch, chassisID, chassisPowerInfoPowerControl, wg4)
                                }

                                // powerSupply
                                chassisPowerInfoPowerSupplies := chassisPowerInfo.PowerSupplies
-                               wg4 := &sync.WaitGroup{}
-                               wg4.Add(len(chassisPowerInfoPowerSupplies))
+                               wg5 := &sync.WaitGroup{}
+                               wg5.Add(len(chassisPowerInfoPowerSupplies))
                                for _, chassisPowerInfoPowerSupply := range chassisPowerInfoPowerSupplies {
-
-                                       go parseChassisPowerInfoPowerSupply(ch, chassisID, chassisPowerInfoPowerSupply, wg4)
+                                       go parseChassisPowerInfoPowerSupply(ch, chassisID, chassisPowerInfoPowerSupply, wg5)
                                }
                        }

@@ -331,13 +345,22 @@ func parseChassisPowerInfoVoltage(ch chan<- prometheus.Metric, chassisID string,
        chassisPowerInfoVoltageID := chassisPowerInfoVoltage.MemberID
        chassisPowerInfoVoltageNameReadingVolts := chassisPowerInfoVoltage.ReadingVolts
        chassisPowerInfoVoltageState := chassisPowerInfoVoltage.Status.State
-       chassisPowerVotageLabelvalues := []string{"power_votage", chassisID, chassisPowerInfoVoltageName, chassisPowerInfoVoltageID}
+       chassisPowerVotageLabelvalues := []string{"power_voltage", chassisID, chassisPowerInfoVoltageName, chassisPowerInfoVoltageID}
        if chassisPowerInfoVoltageStateValue, ok := parseCommonStatusState(chassisPowerInfoVoltageState); ok {
                ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_power_voltage_state"].desc, prometheus.GaugeValue, chassisPowerInfoVoltageStateValue, chassisPowerVotageLabelvalues...)
        }
        ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_power_voltage_volts"].desc, prometheus.GaugeValue, float64(chassisPowerInfoVoltageNameReadingVolts), chassisPowerVotageLabelvalues...)
 }

+func parseChassisPowerInfoPowerControl(ch chan<- prometheus.Metric, chassisID string, chassisPowerInfoPowerControl redfish.PowerControl, wg *sync.WaitGroup) {
+       defer wg.Done()
+       name := chassisPowerInfoPowerControl.Name
+       id := chassisPowerInfoPowerControl.MemberID
+       pm := chassisPowerInfoPowerControl.PowerMetrics
+       chassisPowerVotageLabelvalues := []string{"power_wattage", chassisID, name, id}
+       ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_power_average_consumed_watts"].desc, prometheus.GaugeValue, float64(pm.AverageConsumedWatts), chassisPowerVotageLabelvalues...)
+}
+
 func parseChassisPowerInfoPowerSupply(ch chan<- prometheus.Metric, chassisID string, chassisPowerInfoPowerSupply redfish.PowerSupply, wg *sync.WaitGroup) {

        defer wg.Done()

My apologies for some other modifications in the patch, it's from my local fork.

jenningsloy318 commented 4 years ago

Hi bluecmd, did you have tested it ? also if passed, a pull request is welcome.

bluecmd commented 4 years ago

Yep, I'm using it to monitor some Supermicro servers. It might take some time until I get around to doing a PR, but if you want to use this you can have it - you don't even have to attribute me, it's just a few lines after all.

jenningsloy318 commented 4 years ago

Hi Bluecmd, thanks for your contribution, will merged this metrics into the code.