-
Notifications
You must be signed in to change notification settings - Fork 214
feat(power): add virtual machine power monitoring #2100
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
feat(power): add virtual machine power monitoring #2100
Conversation
@vprashar2929 could you please help test this? |
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.
some initial comment. continuing to review
23be1a3
to
c0a6f4c
Compare
Signed-off-by: Sunil Thaha <sthaha@redhat.com>
Signed-off-by: Sunil Thaha <sthaha@redhat.com>
Add support for monitoring Virtual Machines (VMs). Key changes include: - Enhance a process type to the Process struct - Add `VirtualMachine` struct and `VirtualMachines` map to track VM metadata. - Detect VM processes using regex pattern for QEMU - Enhance `Process` struct with `Type` and `VirtualMachineID` fields to associate processes with VMs. - Add `VirtualMachines()` method to `Informer` interface - Include mock support for VM testing in `mock_utils.go`. *NOTE:* Only Qemu based VMs are supported. VirtualBox, VMware, and Xen hypervisor support are pending Signed-off-by: Sunil Thaha <sthaha@redhat.com>
Add VM power computation just like Container. Signed-off-by: Sunil Thaha <sthaha@redhat.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## reboot #2100 +/- ##
==========================================
+ Coverage 91.97% 92.55% +0.57%
==========================================
Files 30 32 +2
Lines 2143 2538 +395
==========================================
+ Hits 1971 2349 +378
- Misses 137 150 +13
- Partials 35 39 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Sunil Thaha <sthaha@redhat.com>
} | ||
|
||
return nil | ||
} | ||
|
||
// Buffered channels prevent goroutine blocking |
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.
nit: incorrect code comment
@@ -44,6 +45,11 @@ func newProcess(proc *resource.Process, zones ZoneUsageMap) *Process { | |||
if proc.Container != nil { | |||
process.ContainerID = proc.Container.ID | |||
} | |||
|
|||
// Add the container ID if available |
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.
add VmID
|
||
CPUTotalTime float64 // CPU time in seconds | ||
|
||
// Replace single Usage with ZoneUsageMap |
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.
nit: comment needed?
|
||
// Container represents the power consumption of a container | ||
type VirtualMachine struct { | ||
ID string // VM ID |
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.
VM ID has a different meaning. better call it uuid
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.
need not be uuid for other hypervisors ... Say in future, we support vmware, then the unique id (how ever they generate) will still be ID in kepler. vendor specific labels should be published as <vendor>_<label>
. E.g. libvirt_id
if we are to ever add it.
func (pm *PowerMonitor) calculateVMPower(prev, newSnapshot *Snapshot) error { | ||
vms := pm.resources.VirtualMachines() | ||
|
||
// Skip if no containers |
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.
nit: remove/change comment
vmMap := make(VirtualMachines, len(vms.Running)) | ||
|
||
// For each VM, calculate power for each zone separately | ||
for id, c := range vms.Running { |
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.
nit: change c
to vm
, the type is VirtualMachine
continue | ||
} | ||
|
||
cpuTimeRatio := c.CPUTimeDelta / vms.NodeCPUTimeDelta |
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.
wouldn't it be simpler to use power usages from the vm's process power usage directly?
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.
Thats assuming that any vm will have only a single process - right?
if vm == nil { | ||
panic(fmt.Sprintf("process %d of type %s has is nil virtual machine", proc.PID, proc.Type)) |
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.
function panics if proc.VirtualMachine is nil, but the function's usage already invokes proc.VirtualMachine.ID
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.
yes, you are right, but I explicitly wanted to assert and log the process that puts kepler in this specific state that is invalid.
This commit addresses comments on sustainable-computing-io#2100 Signed-off-by: Sunil Thaha <sthaha@redhat.com>
cleanup(vm): addresses comments from #2100
Introduce support for monitoring power consumption of virtual machines (VMs) and expose those as Prometheus metrics
kepler_vm_<rapl-zone>_{watts|joules_total}
.Key changes include:
VirtualMachine
struct andVirtualMachines
map to track VM metadata.Process
struct withType
andVirtualMachineID
fields to associate processes with VMs.VirtualMachines()
method toInformer
interfacemock_utils.go
.NOTE: Only Qemu based VM detetion is supported. VirtualBox, VMware, and Xen hypervisor support are pending