client: fix unallocated CPU metric when reserved cpu is set. (#20543)

This commit is contained in:
James Rasell
2024-05-09 11:55:22 +02:00
committed by GitHub
parent 8620fdca85
commit 7e42ad869a
2 changed files with 8 additions and 1 deletions

3
.changelog/20543.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:bug
client: Fix unallocated CPU metric calculation when client reserved CPU is set
```

View File

@@ -3252,7 +3252,11 @@ func (c *Client) setGaugeForAllocationStats(nodeID string, baseLabels []metrics.
// Emit unallocated
unallocatedMem := total.Memory.MemoryMB - res.Memory.MemoryMB - allocated.Flattened.Memory.MemoryMB
unallocatedDisk := total.Disk.DiskMB - res.Disk.DiskMB - allocated.Shared.DiskMB
unallocatedCpu := int64(total.Processors.Topology.UsableCompute()) - res.Cpu.CpuShares - allocated.Flattened.Cpu.CpuShares
// The UsableCompute function call already subtracts and accounts for any
// reserved CPU within the client configuration. Therefore, we do not need
// to subtract that here.
unallocatedCpu := int64(total.Processors.Topology.UsableCompute()) - allocated.Flattened.Cpu.CpuShares
metrics.SetGaugeWithLabels([]string{"client", "unallocated", "memory"}, float32(unallocatedMem), baseLabels)
metrics.SetGaugeWithLabels([]string{"client", "unallocated", "disk"}, float32(unallocatedDisk), baseLabels)