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.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. ClusterId int64 `json:"clusterId"`
  18. ClusterName string `json:"clusterName"`
  19. Metrics []tracker.Metric `json:"metrics"`
  20. }
  21. func NewClustersLoadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClustersLoadLogic {
  22. return &ClustersLoadLogic{
  23. Logger: logx.WithContext(ctx),
  24. ctx: ctx,
  25. svcCtx: svcCtx,
  26. }
  27. }
  28. func (l *ClustersLoadLogic) ClustersLoad(req *types.ClustersLoadReq) (resp *types.ClustersLoadResp, err error) {
  29. resp = &types.ClustersLoadResp{}
  30. // 查询集群列表
  31. var clustersModel []models.ComputeCluster
  32. l.svcCtx.DbEngin.Raw("select * from t_cluster where label = 'kubernetes'").Scan(&clustersModel)
  33. var result []ClusterInfo
  34. for _, cluster := range clustersModel {
  35. 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"}
  36. data := l.svcCtx.PromClient.GetNamedMetrics(metrics, time.Now(), tracker.ClusterOption{ClusterName: cluster.Name.String})
  37. clusterInfo := ClusterInfo{
  38. ClusterId: cluster.Id,
  39. ClusterName: cluster.Name.String,
  40. Metrics: data,
  41. }
  42. result = append(result, clusterInfo)
  43. }
  44. resp.Data = result
  45. return resp, nil
  46. }

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.