c_resource.go 1.3 KB

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