修改监控接口入参

This commit is contained in:
zhangwei 2025-06-04 19:35:15 +08:00
parent 9689b94964
commit 9ab1d007e4
6 changed files with 33 additions and 11 deletions

View File

@ -121,7 +121,6 @@ type Cloud {
}
type PodsListReq {
ClusterName string `form:"clusterName"`
}
type PodsListResp {
Data []interface{} `json:"data"`

View File

@ -102,7 +102,7 @@ type remoteResp {
type (
clustersLoadReq {
ClusterName string `form:"clusterName"`
}
clustersLoadResp {
Data interface{} `json:"data"`

View File

@ -22,6 +22,11 @@ type ParticipantResp struct {
Data *v1.PodList `json:"data"` // 改成结构体
}
type ClusterInfo struct {
Name string `json:"name"`
Server string `json:"server"`
}
func NewPodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PodsListLogic {
return &PodsListLogic{
Logger: logx.WithContext(ctx),
@ -33,14 +38,14 @@ func NewPodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PodsList
func (l *PodsListLogic) PodsList(req *types.PodsListReq) (resp *types.PodsListResp, err error) {
resp = &types.PodsListResp{}
// query cluster http url.
var apiServerList []string
l.svcCtx.DbEngin.Raw("select server from t_adapter where resource_type = '01'").Scan(&apiServerList)
for _, server := range apiServerList {
var clusterInfoList []ClusterInfo
l.svcCtx.DbEngin.Raw("select ta.server,tc.name from t_adapter ta,t_cluster tc where ta.id = tc.adapter_id and ta.resource_type = '01'").Scan(&clusterInfoList)
for _, clusterInfo := range clusterInfoList {
participantResp := ParticipantResp{}
param := map[string]string{
"clusterName": req.ClusterName,
"clusterName": clusterInfo.Name,
}
httputils.HttpGetWithResult(param, server+"/api/v1/pod/list", &participantResp)
httputils.HttpGetWithResult(param, clusterInfo.Server+"/api/v1/pod/list", &participantResp)
resp.Data = append(resp.Data, participantResp.Data)
}

View File

@ -53,6 +53,8 @@ func (l *ScreenPageTaskLogic) ScreenPageTask(req *types.PageTaskReq) (resp *type
return nil, result.NewDefaultError(err.Error())
}
// 运行卡时数
// 查询任务列表
if err := db.Limit(limit).Offset(offset).Order("created_time desc").Find(&list).Error; err != nil {
return nil, result.NewDefaultError(err.Error())

View File

@ -2,6 +2,7 @@ package monitoring
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/tracker"
"time"
@ -17,6 +18,11 @@ type ClustersLoadLogic struct {
svcCtx *svc.ServiceContext
}
type ClusterInfo struct {
ClusterName string `json:"clusterName"`
Metrics []tracker.Metric `json:"metrics"`
}
func NewClustersLoadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClustersLoadLogic {
return &ClustersLoadLogic{
Logger: logx.WithContext(ctx),
@ -27,8 +33,20 @@ func NewClustersLoadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Clus
func (l *ClustersLoadLogic) ClustersLoad(req *types.ClustersLoadReq) (resp *types.ClustersLoadResp, err error) {
resp = &types.ClustersLoadResp{}
metrics := []string{"cluster_cpu_utilisation", "cluster_cpu_avail", "cluster_cpu_total", "cluster_memory_total", "cluster_memory_avail", "cluster_memory_utilisation", "cluster_disk_utilisation", "cluster_disk_avail", "cluster_disk_total", "cluster_pod_utilisation", "cluster_node_count"}
result := l.svcCtx.PromClient.GetNamedMetrics(metrics, time.Now(), tracker.ClusterOption{ClusterName: req.ClusterName})
// 查询集群列表
var clustersModel []models.ComputeCluster
l.svcCtx.DbEngin.Raw("select * from t_cluster where label = 'kubernetes'").Scan(&clustersModel)
var result []ClusterInfo
for _, cluster := range clustersModel {
metrics := []string{"cluster_cpu_utilisation", "cluster_cpu_avail", "cluster_cpu_total", "cluster_memory_total", "cluster_memory_avail", "cluster_memory_utilisation", "cluster_disk_utilisation", "cluster_disk_avail", "cluster_disk_total", "cluster_pod_utilisation", "cluster_node_count"}
data := l.svcCtx.PromClient.GetNamedMetrics(metrics, time.Now(), tracker.ClusterOption{ClusterName: cluster.Name.String})
clusterInfo := ClusterInfo{
ClusterName: cluster.Name.String,
Metrics: data,
}
result = append(result, clusterInfo)
}
resp.Data = result
return resp, nil
}

View File

@ -90,7 +90,6 @@ type RemoteResp struct {
}
type ClustersLoadReq struct {
ClusterName string `form:"clusterName"`
}
type ClustersLoadResp struct {
@ -5738,7 +5737,6 @@ type Cloud struct {
}
type PodsListReq struct {
ClusterName string `form:"clusterName"`
}
type PodsListResp struct {