mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-28 19:45:07 +08:00
feat(region,host): hostpinger add cpu usage percent report (#22006)
This commit is contained in:
@@ -531,7 +531,8 @@ type SHostStorageStat struct {
|
||||
type SHostPingInput struct {
|
||||
WithData bool `json:"with_data"`
|
||||
|
||||
MemoryUsedMb int `json:"memory_used_mb"`
|
||||
MemoryUsedMb int `json:"memory_used_mb"`
|
||||
CpuUsagePercent float64 `json:"cpu_usage_percent"`
|
||||
|
||||
RootPartitionUsedCapacityMb int `json:"root_partition_used_capacity_mb"`
|
||||
|
||||
|
||||
@@ -4718,6 +4718,7 @@ func (hh *SHost) PerformPing(ctx context.Context, userCred mcclient.TokenCredent
|
||||
}
|
||||
hh.SetMetadata(ctx, "root_partition_used_capacity_mb", input.RootPartitionUsedCapacityMb, userCred)
|
||||
hh.SetMetadata(ctx, "memory_used_mb", input.MemoryUsedMb, userCred)
|
||||
hh.SetMetadata(ctx, "cpu_usage_percent", input.CpuUsagePercent, userCred)
|
||||
|
||||
guests, _ := hh.GetGuests()
|
||||
for _, guest := range guests {
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -110,6 +111,7 @@ func (p *SHostPingTask) payload() api.SHostPingInput {
|
||||
p.lastStatAt = now
|
||||
data = storageman.GatherHostStorageStats(p.masterHostStorages)
|
||||
data.WithData = true
|
||||
data.QgaRunningGuestIds = guestman.GetGuestManager().GetQgaRunningGuests()
|
||||
info, err := mem.VirtualMemory()
|
||||
if err != nil {
|
||||
return data
|
||||
@@ -118,7 +120,13 @@ func (p *SHostPingTask) payload() api.SHostPingInput {
|
||||
memFree := int(info.Available / 1024 / 1024)
|
||||
memUsed := memTotal - memFree
|
||||
data.MemoryUsedMb = memUsed
|
||||
data.QgaRunningGuestIds = guestman.GetGuestManager().GetQgaRunningGuests()
|
||||
cpuUsage, err := cpu.Percent(time.Second, false)
|
||||
if err != nil {
|
||||
return data
|
||||
}
|
||||
if len(cpuUsage) > 0 {
|
||||
data.CpuUsagePercent = cpuUsage[0]
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user