updated shuguangAi GetResourceStats
Former-commit-id: 2e69f551307dd1be671f0cc535b541760ff59aa6
This commit is contained in:
parent
08138fe02e
commit
d56e4bd69f
|
@ -267,12 +267,15 @@ func (s *ShuguangAi) QuerySpecs() (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ShuguangAi) GetResourceStats() (*collector.ResourceStats, error) {
|
func (s *ShuguangAi) GetResourceStats() (*collector.ResourceStats, error) {
|
||||||
|
//balance
|
||||||
userReq := &hpcAC.GetUserInfoReq{}
|
userReq := &hpcAC.GetUserInfoReq{}
|
||||||
userinfo, err := s.svcCtx.ACRpc.GetUserInfo(s.ctx, userReq)
|
userinfo, err := s.svcCtx.ACRpc.GetUserInfo(s.ctx, userReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
balance, _ := strconv.ParseFloat(userinfo.Data.AccountBalance, 64)
|
||||||
|
|
||||||
|
//resource limit
|
||||||
limitReq := &hpcAC.QueueReq{}
|
limitReq := &hpcAC.QueueReq{}
|
||||||
limitResp, err := s.svcCtx.ACRpc.QueryUserQuotasLimit(s.ctx, limitReq)
|
limitResp, err := s.svcCtx.ACRpc.QueryUserQuotasLimit(s.ctx, limitReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -281,20 +284,54 @@ func (s *ShuguangAi) GetResourceStats() (*collector.ResourceStats, error) {
|
||||||
totalCpu := limitResp.Data.AccountMaxCpu
|
totalCpu := limitResp.Data.AccountMaxCpu
|
||||||
totalDcu := limitResp.Data.AccountMaxDcu
|
totalDcu := limitResp.Data.AccountMaxDcu
|
||||||
|
|
||||||
|
//disk
|
||||||
diskReq := &hpcAC.ParaStorQuotaReq{}
|
diskReq := &hpcAC.ParaStorQuotaReq{}
|
||||||
diskResp, err := s.svcCtx.ACRpc.ParaStorQuota(s.ctx, diskReq)
|
diskResp, err := s.svcCtx.ACRpc.ParaStorQuota(s.ctx, diskReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
totalDisk := common.RoundFloat(diskResp.Data[0].Threshold*KB*KB, 3)
|
totalDisk := common.RoundFloat(diskResp.Data[0].Threshold*KB*KB*KB, 3)
|
||||||
availDisk := common.RoundFloat((diskResp.Data[0].Threshold-diskResp.Data[0].Usage)*KB*KB, 3)
|
availDisk := common.RoundFloat((diskResp.Data[0].Threshold-diskResp.Data[0].Usage)*KB*KB*KB, 3)
|
||||||
|
|
||||||
generalInfo, err := s.svcCtx.ACRpc.GetGeneralInfo(s.ctx, nil)
|
//memory
|
||||||
memSize := common.RoundFloat(float64(generalInfo.MemoryInGib)*KB*KB, 3)
|
nodeResp, err := s.svcCtx.ACRpc.GetNodeResources(s.ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
memSize := common.RoundFloat(float64(nodeResp.Data.MemorySize)*KB*KB, 3) // MB to BYTES
|
||||||
|
|
||||||
|
//resources being occupied
|
||||||
|
memberJobResp, err := s.svcCtx.ACRpc.GetMemberJobs(s.ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var CpuCoreAvail int64
|
||||||
|
var MemAvail float64
|
||||||
|
if len(memberJobResp.Data) != 0 {
|
||||||
|
CpuCoreAvail = totalCpu
|
||||||
|
MemAvail = memSize
|
||||||
|
} else {
|
||||||
|
var cpuCoreUsed int64
|
||||||
|
var memUsed float64
|
||||||
|
for _, datum := range memberJobResp.Data {
|
||||||
|
cpuCoreUsed += datum.CpuCore
|
||||||
|
}
|
||||||
|
memUsed = float64(cpuCoreUsed * 2 * KB * KB * KB) // 2 GB per cpu core
|
||||||
|
if cpuCoreUsed > totalCpu {
|
||||||
|
CpuCoreAvail = 0
|
||||||
|
} else {
|
||||||
|
CpuCoreAvail = totalCpu - cpuCoreUsed
|
||||||
|
}
|
||||||
|
if memUsed > memSize {
|
||||||
|
MemAvail = 0
|
||||||
|
} else {
|
||||||
|
MemAvail = memSize - memUsed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//usable hours
|
||||||
var cards []*collector.Card
|
var cards []*collector.Card
|
||||||
balance, _ := strconv.ParseFloat(userinfo.Data.AccountBalance, 64)
|
|
||||||
cardHours := common.RoundFloat(balance/DCUPRICEPERHOUR, 3)
|
cardHours := common.RoundFloat(balance/DCUPRICEPERHOUR, 3)
|
||||||
cpuHours := common.RoundFloat(balance/CPUCOREPRICEPERHOUR, 3)
|
cpuHours := common.RoundFloat(balance/CPUCOREPRICEPERHOUR, 3)
|
||||||
|
|
||||||
|
@ -312,11 +349,11 @@ func (s *ShuguangAi) GetResourceStats() (*collector.ResourceStats, error) {
|
||||||
Name: s.platform,
|
Name: s.platform,
|
||||||
Balance: balance,
|
Balance: balance,
|
||||||
CpuCoreTotal: totalCpu,
|
CpuCoreTotal: totalCpu,
|
||||||
CpuCoreAvail: 0,
|
CpuCoreAvail: CpuCoreAvail,
|
||||||
DiskTotal: totalDisk,
|
DiskTotal: totalDisk,
|
||||||
DiskAvail: availDisk,
|
DiskAvail: availDisk,
|
||||||
MemTotal: memSize,
|
MemTotal: memSize,
|
||||||
MemAvail: 0,
|
MemAvail: MemAvail,
|
||||||
CpuCoreHours: cpuHours,
|
CpuCoreHours: cpuHours,
|
||||||
CardsAvail: cards,
|
CardsAvail: cards,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue