c_resource.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package config
  2. import (
  3. "cicv-data-closedloop/common/config/c_log"
  4. "cicv-data-closedloop/common/util"
  5. "encoding/json"
  6. "time"
  7. )
  8. // SendResourceUsage 保存资源占用情况
  9. func SendResourceUsage() {
  10. for {
  11. time.Sleep(time.Duration(1) * time.Second)
  12. top10Cpu, top10Mem := util.GetTop10CpuAndMem()
  13. top10CpuJson, _ := json.MarshalIndent(top10Cpu, "", " ")
  14. top10MemJson, _ := json.MarshalIndent(top10Mem, "", " ")
  15. responseString, err := util.HttpPostJsonWithHeaders(
  16. CloudConfig.Monitor.Url,
  17. map[string]string{"Authorization": "U9yKpD6kZZDDe4LFKK6myAxBUT1XRrDM"},
  18. map[string]string{
  19. "totalCpuUsage": util.ToString(util.GetCpuPercent()),
  20. "totalMemoryUsage": util.ToString(util.GetMemoryPercent()),
  21. "top10Process": string(top10CpuJson),
  22. "top10Cpu": string(top10CpuJson),
  23. "top10Mem": string(top10MemJson),
  24. "deviceNumber": LocalConfig.EquipmentNo,
  25. "socIp": LocalConfig.Node.Ip,
  26. },
  27. )
  28. if err != nil {
  29. c_log.GlobalLogger.Errorf("发送数据监控信息报错%v,响应信息为:%v", err, responseString)
  30. }
  31. //c_log.GlobalLogger.Infof("发送数据监控信息成功,响应信息为:%v", responseString)
  32. }
  33. }