-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test, don't merge: hmc support #1256
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
/* | ||
Copyright 2022. | ||
Copyright 2023. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
|
@@ -16,21 +13,127 @@ limitations under the License. | |
|
||
package source | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
|
||
"k8s.io/klog/v2" | ||
"github.com/sustainable-computing-io/kepler/pkg/sensors/components/source" | ||
"github.com/zhmcclient/golang-zhmcclient/pkg/zhmcclient" | ||
) | ||
|
||
var hmcManager *zhmcclient.ZhmcManager | ||
|
||
type PowerHMC struct{} | ||
|
||
func (a *PowerHMC) GetName() string { | ||
return "hmc" | ||
func (r *PowerHMC) GetName() string { | ||
return "hmc" | ||
} | ||
|
||
func (r *PowerHMC) GetHMCManager() *zhmcclient.ZhmcManager { | ||
if hmcManager == nil { | ||
endpoint := os.Getenv("HMC_ENDPOINT") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure we should add a PREFIX such as Z_ so it will be easier for other platform to know it's for z only? |
||
username := os.Getenv("HMC_USERNAME") | ||
password := os.Getenv("HMC_PASSWORD") | ||
cacert := os.Getenv("CA_CERT") | ||
skipCert := os.Getenv("SKIP_CERT") | ||
isSkipCert, _ := strconv.ParseBool(skipCert) | ||
|
||
creds := &zhmcclient.Options{Username: username, Password: password, CaCert: cacert, SkipCert: isSkipCert, Trace: false} | ||
client, err := zhmcclient.NewClient(endpoint, creds, nil) | ||
if err != nil { | ||
klog.V(1).Infof("Error getting client connection %v", err.Message) | ||
} | ||
if client != nil { | ||
zhmcAPI := zhmcclient.NewManagerFromClient(client) | ||
hmcManager, _ := zhmcAPI.(*zhmcclient.ZhmcManager) | ||
return hmcManager | ||
} | ||
} | ||
return hmcManager | ||
} | ||
|
||
func (r *PowerHMC) GetEnergyFromLpar() (uint64, error) { | ||
hmcManager := r.GetHMCManager() | ||
lparURI := "api/logical-partitions/" + os.Getenv("LPAR_ID") | ||
props := &zhmcclient.EnergyRequestPayload{ | ||
Range: "last-day", | ||
Resolution: "fifteen-minutes", | ||
} | ||
energy, _, err := hmcManager.GetEnergyDetailsforLPAR(lparURI, props) | ||
if err != nil { | ||
klog.V(1).Infof("Error getting energy data: %v", err.Message) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this need return error ? |
||
} | ||
klog.V(1).Infof("Get energy data successfully") | ||
return energy, err | ||
} | ||
|
||
func (r *PowerHMC) GetLiveEnergyFromLpar() (uint64, error) { | ||
hmcManager := r.GetHMCManager() | ||
lparURI := "/api/logical-partitions/" + os.Getenv("LPAR_ID") | ||
energy, _, err := hmcManager.GetLiveEnergyDetailsforLPAR(lparURI) | ||
if err != nil { | ||
klog.V(1).Infof("Error getting energy data: %v", err.Message) | ||
} else { | ||
klog.V(1).Infof("Get energy data successfully with power: %v", energy) | ||
} | ||
return energy, err | ||
} | ||
|
||
func (r *PowerHMC) IsSystemCollectionSupported() bool { | ||
return true | ||
} | ||
|
||
func (r *PowerHMC) StopPower() { | ||
} | ||
|
||
func (r *PowerHMC) GetEnergyFromDram() (uint64, error) { | ||
return 0, nil | ||
} | ||
|
||
func (r *PowerHMC) GetEnergyFromCore() (uint64, error) { | ||
return 0, nil | ||
} | ||
|
||
func (r *PowerHMC) GetEnergyFromUncore() (uint64, error) { | ||
return 0, nil | ||
} | ||
|
||
func (r *PowerHMC) GetEnergyFromPackage() (uint64, error) { | ||
return 0, nil | ||
} | ||
|
||
func (r *PowerHMC) GetNodeComponentsEnergy() map[int]source.NodeComponentsEnergy { | ||
pkgEnergy, _ := r.GetLiveEnergyFromLpar() | ||
pkgEnergy = pkgEnergy * 3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we can write some info here about why we need this *3 |
||
coreEnergy := uint64(0) | ||
dramEnergy := uint64(0) | ||
uncoreEnergy := uint64(0) | ||
componentsEnergies := make(map[int]source.NodeComponentsEnergy) | ||
componentsEnergies[0] = source.NodeComponentsEnergy{ | ||
Core: coreEnergy, | ||
DRAM: dramEnergy, | ||
Uncore: uncoreEnergy, | ||
Pkg: pkgEnergy, | ||
} | ||
return componentsEnergies | ||
} | ||
|
||
func (a *PowerHMC) StopPower() { | ||
func (r *PowerHMC) GetPlatformEnergy() map[string]float64 { | ||
pkgEnergy, _ := r.GetLiveEnergyFromLpar() | ||
platformEnergies := make(map[string]float64) | ||
platformEnergies["hmc"] = float64(pkgEnergy) * 3 | ||
return platformEnergies | ||
} | ||
|
||
func (a *PowerHMC) IsSystemCollectionSupported() bool { | ||
return false | ||
func (r *PowerHMC) IsPlatformCollectionSupported() bool { | ||
return true | ||
} | ||
|
||
// GetEnergyFromHost returns the accumulated energy consumption | ||
func (a *PowerHMC) GetAbsEnergyFromPlatform() (map[string]float64, error) { | ||
power := map[string]float64{} | ||
return power, nil | ||
func (r *PowerHMC) GetAbsEnergyFromPlatform() (map[string]float64, error) { | ||
pkgEnergy, _ := r.GetLiveEnergyFromLpar() | ||
platformEnergies := make(map[string]float64) | ||
platformEnergies["hmc"] = float64(pkgEnergy) * 3 | ||
return platformEnergies, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we think about zhmc as it's for z/s390x ?