fix: 域信息查询数算集群监控
Signed-off-by: devad <cossjie@foxmail.com> Former-commit-id: 15f598faac392865f3e668136339e741811b7613
This commit is contained in:
parent
c5df5b1292
commit
4549ff388b
|
@ -329,11 +329,21 @@ type (
|
|||
DomainSource int64 `json:"domainSource"` // 资源域数据来源:0-nudt,1-鹏城
|
||||
Stack string `json:"stack"` // 技术栈
|
||||
ResourceType string `json:"resourceType"` // 资源类型
|
||||
Cpu string `json:"cpu"` // cpu
|
||||
Memory string `json:"memory"` // 内存
|
||||
Disk string `json:"disk"` // 存储
|
||||
NodeCount string `json:"nodeCount"` //节点数量
|
||||
Cpu float64 `json:"cpu"` // cpu使用率
|
||||
Memory float64 `json:"memory"` // 内存使用率
|
||||
Disk float64 `json:"disk"` // 存储使用率
|
||||
NodeCount float64 `json:"nodeCount"` //节点使用率
|
||||
// DeleteFlag int64 `json:"delete_flag"` // 是否删除 0:未删除,1:已经删除
|
||||
Description string `json:"description"` //集群描述
|
||||
ClusterName string `json:"clusterName"` //集群名称
|
||||
CpuTotal float64 `json:"cpuTotal"` //cpu总核数
|
||||
MemoryTotal float64 `json:"memoryTotal"` //内存总量Gi
|
||||
DiskTotal float64 `json:"diskTotal"` //存储总量GB
|
||||
NodeTotal float64 `json:"nodeTotal"` //容器节点数
|
||||
CpuUsage float64 `json:"cpuUsage"` //cpu已使用核数
|
||||
MemoryUsage float64 `json:"memoryUsage"` //内存已使用Gi
|
||||
DiskUsage float64 `json:"diskUsage"` //存储已使用GB
|
||||
NodeUsage float64 `json:"nodeUsage"` //容器节点已使用
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -379,4 +389,28 @@ type (
|
|||
CreateTime string `json:"createTime"` //创建时间,
|
||||
UpdateTime string `json:"updateTime"` //更新时间
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
//jccSchedule容器集群资源监控 > start
|
||||
type ClusterMetrics struct {
|
||||
Code int `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
Data []MetricResult `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type MetricResult struct {
|
||||
MetricName string `json:"metric_name, omitempty"`
|
||||
MetricData MetricData `json:"data, omitempty"`
|
||||
}
|
||||
|
||||
type MetricData struct {
|
||||
Result []map[string]interface{} `json:"result"`
|
||||
ResultType string `json:"resultType"`
|
||||
}
|
||||
|
||||
type ResultData struct {
|
||||
Status string `json:"status"`
|
||||
Data MetricData `json:"data"`
|
||||
}
|
||||
//jccSchedule容器集群资源监控 >end
|
|
@ -33,4 +33,5 @@ type Config struct {
|
|||
CephRpcConf zrpc.RpcClientConf
|
||||
OctopusRpcConf zrpc.RpcClientConf
|
||||
NexusUrl string
|
||||
JccScheduleUrl string
|
||||
}
|
||||
|
|
|
@ -6,11 +6,12 @@ import (
|
|||
"PCM/adaptor/PCM-CORE/model"
|
||||
"PCM/common/tool"
|
||||
"context"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"fmt"
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"k8s.io/apimachinery/pkg/util/json"
|
||||
"math"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ListDomainResourceLogic struct {
|
||||
|
@ -28,23 +29,218 @@ func NewListDomainResourceLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||
}
|
||||
|
||||
func (l *ListDomainResourceLogic) ListDomainResource() (resp *types.DomainResourceResp, err error) {
|
||||
|
||||
//TODO 域信息查询数算集群监控
|
||||
resp = &types.DomainResourceResp{}
|
||||
var domainResourceModel []model.DomainResource
|
||||
sqlStr := `select * from domain_resource where delete_flag=0 order by id`
|
||||
sqlStr := "select * from `joint_domain`.domain_cluster"
|
||||
l.svcCtx.DbEngin.Raw(sqlStr).Scan(&domainResourceModel)
|
||||
tool.Convert(domainResourceModel, &resp.DomainResourceList)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
//TODO rand
|
||||
metrics := &types.ClusterMetrics{}
|
||||
//获取指定集群监控数据
|
||||
for i := 0; i < len(resp.DomainResourceList); i++ {
|
||||
c := rand.Intn(65) + 10
|
||||
m := rand.Intn(65) + 10
|
||||
d := rand.Intn(65) + 10
|
||||
n := rand.Intn(65) + 10
|
||||
resp.DomainResourceList[i].Cpu = strconv.Itoa(c)
|
||||
resp.DomainResourceList[i].Memory = strconv.Itoa(m)
|
||||
resp.DomainResourceList[i].Disk = strconv.Itoa(d)
|
||||
resp.DomainResourceList[i].NodeCount = strconv.Itoa(n)
|
||||
url := fmt.Sprintf("%s/api/v1/resource/getClusterMetrics?clusterName=%s", l.svcCtx.Config.JccScheduleUrl, resp.DomainResourceList[i].ClusterName)
|
||||
bytes, err := tool.HttpGet("GET", url)
|
||||
if err != nil {
|
||||
logx.WithContext(l.ctx).Errorf("获取云算指定集群监控数据 err: %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
json.Unmarshal(bytes, metrics)
|
||||
if metrics.Code == 200 {
|
||||
//fmt.Print(metrics)
|
||||
for _, metricResult := range metrics.Data {
|
||||
//集群内存已使用
|
||||
if metricResult.MetricName == "cluster_memory_usage_wo_cache" {
|
||||
format, ok := metricResult.MetricData.Result[0]["values"].([]interface{})
|
||||
if ok {
|
||||
for _, val := range format {
|
||||
f, ok := val.([]interface{})
|
||||
if ok {
|
||||
value, _ := f[1].(string)
|
||||
v1, err := strconv.ParseFloat(value, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
v2, _ := decimal.NewFromFloat(v1 / (1024 * 1024 * 1024)).Round(2).Float64()
|
||||
resp.DomainResourceList[i].MemoryUsage = v2
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
//集群内存总量
|
||||
if metricResult.MetricName == "cluster_memory_total" {
|
||||
format, ok := metricResult.MetricData.Result[0]["values"].([]interface{})
|
||||
if ok {
|
||||
for _, val := range format {
|
||||
f, ok := val.([]interface{})
|
||||
if ok {
|
||||
value, _ := f[1].(string)
|
||||
v1, err := strconv.ParseFloat(value, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
v2, _ := decimal.NewFromFloat(v1 / (1024 * 1024 * 1024)).Round(2).Float64()
|
||||
resp.DomainResourceList[i].MemoryTotal = v2
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
//集群cpu已使用
|
||||
if metricResult.MetricName == "cluster_cpu_usage" {
|
||||
format, ok := metricResult.MetricData.Result[0]["values"].([]interface{})
|
||||
if ok {
|
||||
for _, val := range format {
|
||||
f, ok := val.([]interface{})
|
||||
if ok {
|
||||
value, _ := f[1].(string)
|
||||
v1, err := strconv.ParseFloat(value, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
v2, _ := decimal.NewFromFloat(v1).Round(2).Float64()
|
||||
resp.DomainResourceList[i].CpuUsage = v2
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
//集群cpu总核数
|
||||
if metricResult.MetricName == "cluster_cpu_total" {
|
||||
format, ok := metricResult.MetricData.Result[0]["values"].([]interface{})
|
||||
if ok {
|
||||
for _, val := range format {
|
||||
f, ok := val.([]interface{})
|
||||
if ok {
|
||||
value, _ := f[1].(string)
|
||||
v1, err := strconv.ParseFloat(value, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
v2, _ := decimal.NewFromFloat(v1).Round(2).Float64()
|
||||
resp.DomainResourceList[i].CpuTotal = v2
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
//集群容器节点已使用数量
|
||||
if metricResult.MetricName == "cluster_pod_running_count" {
|
||||
format, ok := metricResult.MetricData.Result[0]["values"].([]interface{})
|
||||
if ok {
|
||||
for _, val := range format {
|
||||
f, ok := val.([]interface{})
|
||||
if ok {
|
||||
value, _ := f[1].(string)
|
||||
v1, err := strconv.ParseFloat(value, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
v2, _ := decimal.NewFromFloat(v1).Round(2).Float64()
|
||||
resp.DomainResourceList[i].NodeUsage = v2
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
//集群容器节点总量
|
||||
if metricResult.MetricName == "cluster_pod_quota" {
|
||||
format, ok := metricResult.MetricData.Result[0]["values"].([]interface{})
|
||||
if ok {
|
||||
for _, val := range format {
|
||||
f, ok := val.([]interface{})
|
||||
if ok {
|
||||
value, _ := f[1].(string)
|
||||
v1, err := strconv.ParseFloat(value, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
v2, _ := decimal.NewFromFloat(v1).Round(2).Float64()
|
||||
resp.DomainResourceList[i].NodeTotal = v2
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
//集群磁盘已使用
|
||||
if metricResult.MetricName == "cluster_disk_size_usage" {
|
||||
format, ok := metricResult.MetricData.Result[0]["values"].([]interface{})
|
||||
if ok {
|
||||
for _, val := range format {
|
||||
f, ok := val.([]interface{})
|
||||
if ok {
|
||||
value, _ := f[1].(string)
|
||||
v1, err := strconv.ParseFloat(value, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
v2, _ := decimal.NewFromFloat(v1 / (1000 * 1000 * 1000)).Round(2).Float64()
|
||||
resp.DomainResourceList[i].DiskUsage = v2
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
//集群磁盘总量
|
||||
if metricResult.MetricName == "cluster_disk_size_capacity" {
|
||||
format, ok := metricResult.MetricData.Result[0]["values"].([]interface{})
|
||||
if ok {
|
||||
for _, val := range format {
|
||||
f, ok := val.([]interface{})
|
||||
if ok {
|
||||
value, _ := f[1].(string)
|
||||
v1, err := strconv.ParseFloat(value, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
v2, _ := decimal.NewFromFloat(v1 / (1000 * 1000 * 1000)).Round(2).Float64()
|
||||
resp.DomainResourceList[i].DiskTotal = v2
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if resp.DomainResourceList[i].CpuUsage != 0 && resp.DomainResourceList[i].CpuTotal != 0 {
|
||||
resp.DomainResourceList[i].Cpu = math.Ceil((resp.DomainResourceList[i].CpuUsage / resp.DomainResourceList[i].CpuTotal) * 10000 / 100.00)
|
||||
}
|
||||
if resp.DomainResourceList[i].NodeUsage != 0 && resp.DomainResourceList[i].NodeTotal != 0 {
|
||||
resp.DomainResourceList[i].NodeCount = math.Ceil((resp.DomainResourceList[i].NodeUsage / resp.DomainResourceList[i].NodeTotal) * 10000 / 100.00)
|
||||
}
|
||||
if resp.DomainResourceList[i].DiskUsage != 0 && resp.DomainResourceList[i].DiskTotal != 0 {
|
||||
resp.DomainResourceList[i].Disk = math.Ceil((resp.DomainResourceList[i].DiskUsage / resp.DomainResourceList[i].DiskTotal) * 10000 / 100.00)
|
||||
}
|
||||
if resp.DomainResourceList[i].MemoryUsage != 0 && resp.DomainResourceList[i].MemoryTotal != 0 {
|
||||
resp.DomainResourceList[i].Memory = math.Ceil((resp.DomainResourceList[i].MemoryUsage / resp.DomainResourceList[i].MemoryTotal) * 10000 / 100.00)
|
||||
}
|
||||
resp.DomainResourceList[i].DomainName = resp.DomainResourceList[i].Description
|
||||
resp.DomainResourceList[i].ResourceType = "云算"
|
||||
resp.DomainResourceList[i].Stack = "kubernetes"
|
||||
}
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
@ -297,17 +297,27 @@ type DomainResourceResp struct {
|
|||
}
|
||||
|
||||
type DomainResource struct {
|
||||
Id int64 `json:"id"` // id
|
||||
DomainId string `json:"domainId"` // 资源域id
|
||||
DomainName string `json:"domainName"` // 资源域名称
|
||||
JobCount int64 `json:"jobCount"` // 资源域任务数量
|
||||
DomainSource int64 `json:"domainSource"` // 资源域数据来源:0-nudt,1-鹏城
|
||||
Stack string `json:"stack"` // 技术栈
|
||||
ResourceType string `json:"resourceType"` // 资源类型
|
||||
Cpu string `json:"cpu"` // cpu
|
||||
Memory string `json:"memory"` // 内存
|
||||
Disk string `json:"disk"` // 存储
|
||||
NodeCount string `json:"nodeCount"` //节点数量
|
||||
Id int64 `json:"id"` // id
|
||||
DomainId string `json:"domainId"` // 资源域id
|
||||
DomainName string `json:"domainName"` // 资源域名称
|
||||
JobCount int64 `json:"jobCount"` // 资源域任务数量
|
||||
DomainSource int64 `json:"domainSource"` // 资源域数据来源:0-nudt,1-鹏城
|
||||
Stack string `json:"stack"` // 技术栈
|
||||
ResourceType string `json:"resourceType"` // 资源类型
|
||||
Cpu float64 `json:"cpu"` // cpu使用率
|
||||
Memory float64 `json:"memory"` // 内存使用率
|
||||
Disk float64 `json:"disk"` // 存储使用率
|
||||
NodeCount float64 `json:"nodeCount"` //节点使用率
|
||||
Description string `json:"description"` //集群描述
|
||||
ClusterName string `json:"clusterName"` //集群名称
|
||||
CpuTotal float64 `json:"cpuTotal"` //cpu总核数
|
||||
MemoryTotal float64 `json:"memoryTotal"` //内存总量Gi
|
||||
DiskTotal float64 `json:"diskTotal"` //存储总量GB
|
||||
NodeTotal float64 `json:"nodeTotal"` //容器节点数
|
||||
CpuUsage float64 `json:"cpuUsage"` //cpu已使用核数
|
||||
MemoryUsage float64 `json:"memoryUsage"` //内存已使用Gi
|
||||
DiskUsage float64 `json:"diskUsage"` //存储已使用GB
|
||||
NodeUsage float64 `json:"nodeUsage"` //容器节点已使用
|
||||
}
|
||||
|
||||
type ResourcePanelConfigReq struct {
|
||||
|
@ -352,6 +362,27 @@ type ResourcePanelConfigResp struct {
|
|||
UpdateTime string `json:"updateTime"` //更新时间
|
||||
}
|
||||
|
||||
type ClusterMetrics struct {
|
||||
Code int `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
Data []MetricResult `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type MetricResult struct {
|
||||
MetricName string `json:"metric_name, omitempty"`
|
||||
MetricData MetricData `json:"data, omitempty"`
|
||||
}
|
||||
|
||||
type MetricData struct {
|
||||
Result []map[string]interface{} `json:"result"`
|
||||
ResultType string `json:"resultType"`
|
||||
}
|
||||
|
||||
type ResultData struct {
|
||||
Status string `json:"status"`
|
||||
Data MetricData `json:"data"`
|
||||
}
|
||||
|
||||
type Job struct {
|
||||
SlurmVersion string `json:"slurmVersion"`
|
||||
Name string `json:"name"`
|
||||
|
|
|
@ -53,6 +53,8 @@ type (
|
|||
CreateTime time.Time `db:"create_time"` // 数据创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 数据更新时间
|
||||
DeleteFlag int64 `db:"delete_flag"` // 是否删除 0:未删除,1:已经删除
|
||||
Description string `db:"description"` //集群描述
|
||||
ClusterName string `db:"cluster_name"` //集群名称
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package tool
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func FloatConv(num float64) float64 {
|
||||
num, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", num), 64)
|
||||
return num
|
||||
}
|
1
go.mod
1
go.mod
|
@ -21,6 +21,7 @@ require (
|
|||
github.com/nacos-group/nacos-sdk-go/v2 v2.2.1
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
github.com/shopspring/decimal v1.3.1
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
github.com/zeromicro/go-queue v1.1.8
|
||||
github.com/zeromicro/go-zero v1.5.1
|
||||
|
|
1
go.sum
1
go.sum
|
@ -991,6 +991,7 @@ github.com/segmentio/kafka-go v0.4.38/go.mod h1:ikyuGon/60MN/vXFgykf7Zm8P5Be49gJ
|
|||
github.com/shirou/gopsutil v2.19.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
|
||||
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
|
||||
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
|
|
Loading…
Reference in New Issue