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.

status_report.go 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package main
  2. import (
  3. "sync"
  4. "time"
  5. log "github.com/sirupsen/logrus"
  6. "gitlink.org.cn/cloudream/agent/internal/config"
  7. coorcli "gitlink.org.cn/cloudream/rabbitmq/client/coordinator"
  8. coormsg "gitlink.org.cn/cloudream/rabbitmq/message/coordinator"
  9. "gitlink.org.cn/cloudream/utils"
  10. "gitlink.org.cn/cloudream/utils/consts"
  11. )
  12. func reportStatus(wg *sync.WaitGroup) {
  13. coorCli, err := coorcli.NewCoordinatorClient(&config.Cfg().RabbitMQ)
  14. if err != nil {
  15. wg.Done()
  16. log.Error("new coordinator client failed, err: %w", err)
  17. return
  18. }
  19. // TODO 增加退出死循环的方法
  20. for {
  21. //挨个ping其他agent(AgentIpList),记录延迟到AgentDelay
  22. // TODO AgentIP考虑放到配置文件里或者启动时从coor获取
  23. ips := utils.GetAgentIps()
  24. agentDelay := make([]int, len(ips))
  25. waitG := sync.WaitGroup{}
  26. waitG.Add(len(ips))
  27. for i := 0; i < len(ips); i++ {
  28. go func(i int, wg *sync.WaitGroup) {
  29. connStatus, err := utils.GetConnStatus(ips[i])
  30. if err != nil {
  31. wg.Done()
  32. log.Warnf("ping %s failed, err: %s", ips[i], err.Error())
  33. return
  34. }
  35. log.Debugf("connection status to %s: %+v", ips[i], connStatus)
  36. if connStatus.IsReachable {
  37. agentDelay[i] = int(connStatus.Delay.Milliseconds()) + 1
  38. } else {
  39. agentDelay[i] = -1
  40. }
  41. wg.Done()
  42. }(i, &waitG)
  43. }
  44. waitG.Wait()
  45. //TODO: 查看本地IPFS daemon是否正常,记录到ipfsStatus
  46. ipfsStatus := consts.IPFS_STATUS_OK
  47. //TODO:访问自身资源目录(配置文件中获取路径),记录是否正常,记录到localDirStatus
  48. localDirStatus := consts.LOCAL_DIR_STATUS_OK
  49. //发送心跳
  50. // TODO 由于数据结构未定,暂时不发送真实数据
  51. coorCli.AgentStatusReport(coormsg.NewAgentStatusReportBody(config.Cfg().ID, []int{}, []int{}, ipfsStatus, localDirStatus))
  52. time.Sleep(time.Minute * 5)
  53. }
  54. coorCli.Close()
  55. wg.Done()
  56. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。