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.

centerresourceslogic.go 2.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package core
  2. import (
  3. "context"
  4. "github.com/prometheus/common/model"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/tracker"
  6. "strconv"
  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 CenterResourcesLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewCenterResourcesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CenterResourcesLogic {
  17. return &CenterResourcesLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. func (l *CenterResourcesLogic) CenterResources() (resp *types.CenterResourcesResp, err error) {
  24. resp = &types.CenterResourcesResp{}
  25. rawData, err := l.svcCtx.PromClient.GetRawData("center_top3", tracker.AdapterOption{})
  26. if err != nil {
  27. return nil, err
  28. }
  29. var centersIndex []*types.CenterIndex
  30. data := rawData.(model.Vector)
  31. for _, d := range data {
  32. for _, v := range d.Metric {
  33. num, err := strconv.ParseInt(string(v), 10, 64)
  34. if err != nil {
  35. return nil, err
  36. }
  37. centersIndex = append(centersIndex, &types.CenterIndex{Id: num})
  38. }
  39. }
  40. for _, centerIndex := range centersIndex {
  41. // Query the types of resource centers
  42. l.svcCtx.DbEngin.Raw("select name,type as CenterType from t_adapter where id = ?", centerIndex.Id).Scan(&centerIndex)
  43. var clustersName string
  44. l.svcCtx.DbEngin.Raw("SELECT GROUP_CONCAT(name SEPARATOR '|' ) as clustersName from t_cluster where adapter_id = ?", centerIndex.Id).Scan(&clustersName)
  45. cpuRawData, err := l.svcCtx.PromClient.GetRawData("center_cpu_utilisation", tracker.AdapterOption{AdapterId: centerIndex.Id, ClustersName: clustersName})
  46. cpuData := cpuRawData.(model.Vector)
  47. if err != nil {
  48. return nil, err
  49. }
  50. centerIndex.Cpu = cpuData[0].Value.String()
  51. memoryRawData, err := l.svcCtx.PromClient.GetRawData("center_memory_utilisation", tracker.AdapterOption{AdapterId: centerIndex.Id, ClustersName: clustersName})
  52. if err != nil {
  53. return nil, err
  54. }
  55. memoryData := memoryRawData.(model.Vector)
  56. centerIndex.Memory = memoryData[0].Value.String()
  57. diskRawData, err := l.svcCtx.PromClient.GetRawData("center_disk_utilisation", tracker.AdapterOption{AdapterId: centerIndex.Id, ClustersName: clustersName})
  58. if err != nil {
  59. return nil, err
  60. }
  61. diskData := diskRawData.(model.Vector)
  62. centerIndex.Storage = diskData[0].Value.String()
  63. resp.CentersIndex = append(resp.CentersIndex, *centerIndex)
  64. }
  65. return resp, nil
  66. }

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.