You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

clustersloadlogic.go 1.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package monitoring
  2. import (
  3. "context"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/tracker"
  6. "time"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type ClustersLoadLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. type ClusterInfo struct {
  17. ClusterName string `json:"clusterName"`
  18. Metrics []tracker.Metric `json:"metrics"`
  19. }
  20. func NewClustersLoadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClustersLoadLogic {
  21. return &ClustersLoadLogic{
  22. Logger: logx.WithContext(ctx),
  23. ctx: ctx,
  24. svcCtx: svcCtx,
  25. }
  26. }
  27. func (l *ClustersLoadLogic) ClustersLoad(req *types.ClustersLoadReq) (resp *types.ClustersLoadResp, err error) {
  28. resp = &types.ClustersLoadResp{}
  29. // 查询集群列表
  30. var clustersModel []models.ComputeCluster
  31. l.svcCtx.DbEngin.Raw("select * from t_cluster where label = 'kubernetes'").Scan(&clustersModel)
  32. var result []ClusterInfo
  33. for _, cluster := range clustersModel {
  34. 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"}
  35. data := l.svcCtx.PromClient.GetNamedMetrics(metrics, time.Now(), tracker.ClusterOption{ClusterName: cluster.Name.String})
  36. clusterInfo := ClusterInfo{
  37. ClusterName: cluster.Name.String,
  38. Metrics: data,
  39. }
  40. result = append(result, clusterInfo)
  41. }
  42. resp.Data = result
  43. return resp, nil
  44. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.