Skip to content

Commit

Permalink
Store powermetrics of machine (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 authored Jan 16, 2023
1 parent 0e7200d commit 755db95
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 24 deletions.
37 changes: 29 additions & 8 deletions cmd/metal-api/internal/metal/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,35 @@ type Fru struct {
// IPMI connection data
type IPMI struct {
// Address is host:port of the connection to the ipmi BMC, host can be either a ip address or a hostname
Address string `rethinkdb:"address" json:"address"`
MacAddress string `rethinkdb:"mac" json:"mac"`
User string `rethinkdb:"user" json:"user"`
Password string `rethinkdb:"password" json:"password"`
Interface string `rethinkdb:"interface" json:"interface"`
Fru Fru `rethinkdb:"fru" json:"fru"`
BMCVersion string `rethinkdb:"bmcversion" json:"bmcversion"`
PowerState string `rethinkdb:"powerstate" json:"powerstate"`
Address string `rethinkdb:"address" json:"address"`
MacAddress string `rethinkdb:"mac" json:"mac"`
User string `rethinkdb:"user" json:"user"`
Password string `rethinkdb:"password" json:"password"`
Interface string `rethinkdb:"interface" json:"interface"`
Fru Fru `rethinkdb:"fru" json:"fru"`
BMCVersion string `rethinkdb:"bmcversion" json:"bmcversion"`
PowerState string `rethinkdb:"powerstate" json:"powerstate"`
PowerMetric *PowerMetric `rethinkdb:"powermetric" json:"powermetric"`
}

type PowerMetric struct {
// AverageConsumedWatts shall represent the
// average power level that occurred averaged over the last IntervalInMin
// minutes.
AverageConsumedWatts float32 `rethinkdb:"averageconsumedwatts" json:"averageconsumedwatts"`
// IntervalInMin shall represent the time
// interval (or window), in minutes, in which the PowerMetrics properties
// are measured over.
// Should be an integer, but some Dell implementations return as a float.
IntervalInMin float32 `rethinkdb:"intervalinmin" json:"intervalinmin"`
// MaxConsumedWatts shall represent the
// maximum power level in watts that occurred within the last
// IntervalInMin minutes.
MaxConsumedWatts float32 `rethinkdb:"maxconsumedwatts" json:"maxconsumedwatts"`
// MinConsumedWatts shall represent the
// minimum power level in watts that occurred within the last
// IntervalInMin minutes.
MinConsumedWatts float32 `rethinkdb:"minconsumedwatts" json:"minconsumedwatts"`
}

// BIOS contains machine bios information
Expand Down
8 changes: 8 additions & 0 deletions cmd/metal-api/internal/service/machine-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,14 @@ func (r *machineResource) ipmiReport(request *restful.Request, response *restful
if report.PowerState != "" {
newMachine.IPMI.PowerState = report.PowerState
}
if report.PowerMetric != nil {
newMachine.IPMI.PowerMetric = &metal.PowerMetric{
AverageConsumedWatts: report.PowerMetric.AverageConsumedWatts,
IntervalInMin: report.PowerMetric.IntervalInMin,
MaxConsumedWatts: report.PowerMetric.MaxConsumedWatts,
MinConsumedWatts: report.PowerMetric.MinConsumedWatts,
}
}

ledstate, err := metal.LEDStateFrom(report.IndicatorLEDState)
if err == nil {
Expand Down
76 changes: 60 additions & 16 deletions cmd/metal-api/internal/service/v1/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,35 @@ type MachineBIOS struct {
}

type MachineIPMI struct {
Address string `json:"address" modelDescription:"The IPMI connection data"`
MacAddress string `json:"mac"`
User string `json:"user"`
Password string `json:"password"`
Interface string `json:"interface"`
Fru MachineFru `json:"fru"`
BMCVersion string `json:"bmcversion"`
PowerState string `json:"powerstate"`
Address string `json:"address" modelDescription:"The IPMI connection data"`
MacAddress string `json:"mac"`
User string `json:"user"`
Password string `json:"password"`
Interface string `json:"interface"`
Fru MachineFru `json:"fru"`
BMCVersion string `json:"bmcversion"`
PowerState string `json:"powerstate"`
PowerMetric *PowerMetric `json:"powermetric"`
}

type PowerMetric struct {
// AverageConsumedWatts shall represent the
// average power level that occurred averaged over the last IntervalInMin
// minutes.
AverageConsumedWatts float32 `json:"averageconsumedwatts"`
// IntervalInMin shall represent the time
// interval (or window), in minutes, in which the PowerMetrics properties
// are measured over.
// Should be an integer, but some Dell implementations return as a float.
IntervalInMin float32 `json:"intervalinmin"`
// MaxConsumedWatts shall represent the
// maximum power level in watts that occurred within the last
// IntervalInMin minutes.
MaxConsumedWatts float32 `json:"maxconsumedwatts"`
// MinConsumedWatts shall represent the
// minimum power level in watts that occurred within the last
// IntervalInMin minutes.
MinConsumedWatts float32 `json:"minconsumedwatts"`
}

type MachineFru struct {
Expand Down Expand Up @@ -221,6 +242,7 @@ type MachineIpmiReport struct {
BMCVersion string
PowerState string
IndicatorLEDState string
PowerMetric *PowerMetric
}

type MachineIpmiReports struct {
Expand Down Expand Up @@ -315,6 +337,15 @@ func NewMetalIPMI(r *MachineIPMI) metal.IPMI {
if r.Fru.ProductSerial != nil {
productSerial = *r.Fru.ProductSerial
}
var powerMetric *metal.PowerMetric
if r.PowerMetric != nil {
powerMetric = &metal.PowerMetric{
AverageConsumedWatts: r.PowerMetric.AverageConsumedWatts,
IntervalInMin: r.PowerMetric.IntervalInMin,
MaxConsumedWatts: r.PowerMetric.MaxConsumedWatts,
MinConsumedWatts: r.PowerMetric.MinConsumedWatts,
}
}

return metal.IPMI{
Address: r.Address,
Expand All @@ -333,23 +364,36 @@ func NewMetalIPMI(r *MachineIPMI) metal.IPMI {
ProductPartNumber: productPartNumber,
ProductSerial: productSerial,
},
PowerState: r.PowerState,
PowerState: r.PowerState,
PowerMetric: powerMetric,
}
}

func NewMachineIPMIResponse(m *metal.Machine, s *metal.Size, p *metal.Partition, i *metal.Image, ec *metal.ProvisioningEventContainer) *MachineIPMIResponse {
machineResponse := NewMachineResponse(m, s, p, i, ec)

var powerMetric *PowerMetric
if m.IPMI.PowerMetric != nil {
powerMetric = &PowerMetric{
AverageConsumedWatts: m.IPMI.PowerMetric.AverageConsumedWatts,
IntervalInMin: m.IPMI.PowerMetric.IntervalInMin,
MaxConsumedWatts: m.IPMI.PowerMetric.MaxConsumedWatts,
MinConsumedWatts: m.IPMI.PowerMetric.MinConsumedWatts,
}
}

return &MachineIPMIResponse{
Common: machineResponse.Common,
MachineBase: machineResponse.MachineBase,
IPMI: MachineIPMI{
Address: m.IPMI.Address,
MacAddress: m.IPMI.MacAddress,
User: m.IPMI.User,
Password: m.IPMI.Password,
Interface: m.IPMI.Interface,
BMCVersion: m.IPMI.BMCVersion,
PowerState: m.IPMI.PowerState,
Address: m.IPMI.Address,
MacAddress: m.IPMI.MacAddress,
User: m.IPMI.User,
Password: m.IPMI.Password,
Interface: m.IPMI.Interface,
BMCVersion: m.IPMI.BMCVersion,
PowerState: m.IPMI.PowerState,
PowerMetric: powerMetric,
Fru: MachineFru{
ChassisPartNumber: &m.IPMI.Fru.ChassisPartNumber,
ChassisPartSerial: &m.IPMI.Fru.ChassisPartSerial,
Expand Down
34 changes: 34 additions & 0 deletions spec/metal-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -2356,6 +2356,9 @@
"password": {
"type": "string"
},
"powermetric": {
"$ref": "#/definitions/v1.PowerMetric"
},
"powerstate": {
"type": "string"
},
Expand All @@ -2370,6 +2373,7 @@
"interface",
"mac",
"password",
"powermetric",
"powerstate",
"user"
]
Expand Down Expand Up @@ -2485,6 +2489,9 @@
"IndicatorLEDState": {
"type": "string"
},
"PowerMetric": {
"$ref": "#/definitions/v1.PowerMetric"
},
"PowerState": {
"type": "string"
}
Expand All @@ -2495,6 +2502,7 @@
"BMCVersion",
"FRU",
"IndicatorLEDState",
"PowerMetric",
"PowerState"
]
},
Expand Down Expand Up @@ -3540,6 +3548,32 @@
"id"
]
},
"v1.PowerMetric": {
"properties": {
"averageconsumedwatts": {
"format": "float",
"type": "number"
},
"intervalinmin": {
"format": "float",
"type": "number"
},
"maxconsumedwatts": {
"format": "float",
"type": "number"
},
"minconsumedwatts": {
"format": "float",
"type": "number"
}
},
"required": [
"averageconsumedwatts",
"intervalinmin",
"maxconsumedwatts",
"minconsumedwatts"
]
},
"v1.Project": {
"properties": {
"description": {
Expand Down

0 comments on commit 755db95

Please sign in to comment.