From 5cc626f161ae3a217649d25bb141ad065fd106c0 Mon Sep 17 00:00:00 2001 From: Joshua Powers Date: Wed, 18 Jan 2023 03:07:52 -0700 Subject: [PATCH] feat(inputs.redfish): Add power control metric (#12496) --- plugins/inputs/redfish/redfish.go | 44 ++++++++++++++++++++++++++ plugins/inputs/redfish/redfish_test.go | 43 +++++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/plugins/inputs/redfish/redfish.go b/plugins/inputs/redfish/redfish.go index 660b9f1d2..16cc994e3 100644 --- a/plugins/inputs/redfish/redfish.go +++ b/plugins/inputs/redfish/redfish.go @@ -53,6 +53,21 @@ type Chassis struct { } type Power struct { + PowerControl []struct { + Name string + MemberID string + PowerAllocatedWatts *float64 + PowerAvailableWatts *float64 + PowerCapacityWatts *float64 + PowerConsumedWatts *float64 + PowerRequestedWatts *float64 + PowerMetrics struct { + AverageConsumedWatts *float64 + IntervalInMin int + MaxConsumedWatts *float64 + MinConsumedWatts *float64 + } + } PowerSupplies []struct { Name string MemberID string @@ -309,6 +324,35 @@ func (r *Redfish) Gather(acc telegraf.Accumulator) error { return err } + for _, j := range power.PowerControl { + tags := map[string]string{ + "member_id": j.MemberID, + "address": address, + "name": j.Name, + "source": system.Hostname, + } + if chassis.Location != nil { + tags["datacenter"] = chassis.Location.PostalAddress.DataCenter + tags["room"] = chassis.Location.PostalAddress.Room + tags["rack"] = chassis.Location.Placement.Rack + tags["row"] = chassis.Location.Placement.Row + } + + fields := map[string]interface{}{ + "power_allocated_watts": j.PowerAllocatedWatts, + "power_available_watts": j.PowerAvailableWatts, + "power_capacity_watts": j.PowerCapacityWatts, + "power_consumed_watts": j.PowerConsumedWatts, + "power_requested_watts": j.PowerRequestedWatts, + "average_consumed_watts": j.PowerMetrics.AverageConsumedWatts, + "interval_in_min": j.PowerMetrics.IntervalInMin, + "max_consumed_watts": j.PowerMetrics.MaxConsumedWatts, + "min_consumed_watts": j.PowerMetrics.MinConsumedWatts, + } + + acc.AddFields("redfish_power_powercontrol", fields, tags) + } + for _, j := range power.PowerSupplies { tags := map[string]string{} tags["member_id"] = j.MemberID diff --git a/plugins/inputs/redfish/redfish_test.go b/plugins/inputs/redfish/redfish_test.go index 04a102014..ebf3b24b2 100644 --- a/plugins/inputs/redfish/redfish_test.go +++ b/plugins/inputs/redfish/redfish_test.go @@ -402,6 +402,31 @@ func TestDellApis(t *testing.T) { }, time.Unix(0, 0), ), + testutil.MustMetric( + "redfish_power_powercontrol", + map[string]string{ + "source": "tpa-hostname", + "name": "System Power Control", + "member_id": "PowerControl", + "address": address, + "datacenter": "", + "rack": "", + "room": "", + "row": "", + }, + map[string]interface{}{ + "average_consumed_watts": 426.0, + "interval_in_min": int64(1), + "max_consumed_watts": 436.0, + "min_consumed_watts": 425.0, + "power_allocated_watts": 1628.0, + "power_available_watts": 0.0, + "power_capacity_watts": 1628.0, + "power_consumed_watts": 429.0, + "power_requested_watts": 704.0, + }, + time.Unix(0, 0), + ), testutil.MustMetric( "redfish_power_powersupplies", map[string]string{ @@ -607,6 +632,24 @@ func TestHPApis(t *testing.T) { }, time.Unix(0, 0), ), + testutil.MustMetric( + "redfish_power_powercontrol", + map[string]string{ + "source": "tpa-hostname", + "name": "", + "member_id": "0", + "address": address, + }, + map[string]interface{}{ + "average_consumed_watts": 221.0, + "interval_in_min": int64(20), + "max_consumed_watts": 252.0, + "min_consumed_watts": 220.0, + "power_capacity_watts": 1600.0, + "power_consumed_watts": 221.0, + }, + time.Unix(0, 0), + ), testutil.MustMetric( "redfish_power_powersupplies", map[string]string{