You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
778 B
Go
28 lines
778 B
Go
package hypervisor
|
|
|
|
type memoryUsageStats struct {
|
|
AvailableKiB *uint64
|
|
UnusedKiB *uint64
|
|
}
|
|
|
|
func estimateMemoryUsedKiB(stats memoryUsageStats) *uint64 {
|
|
if stats.AvailableKiB == nil || stats.UnusedKiB == nil ||
|
|
*stats.UnusedKiB > *stats.AvailableKiB {
|
|
return nil
|
|
}
|
|
used := *stats.AvailableKiB - *stats.UnusedKiB
|
|
return &used
|
|
}
|
|
|
|
// optionalNonNegativeCounter preserves the distinction between a real zero
|
|
// and a counter that the host could not provide. libvirt uses a negative value
|
|
// for an unavailable interface statistic on some drivers; exporting that as
|
|
// zero would make a missing observation look healthy.
|
|
func optionalNonNegativeCounter(set bool, value int64) *uint64 {
|
|
if !set || value < 0 {
|
|
return nil
|
|
}
|
|
result := uint64(value)
|
|
return &result
|
|
}
|