c_resource.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package config
  2. import (
  3. "cicv-data-closedloop/common/config/c_log"
  4. "cicv-data-closedloop/common/util"
  5. "time"
  6. )
  7. //type DeviceMonitor struct {
  8. // Id int `db:"id" json:"id"` // 自增id
  9. // TotalCpuUsage string `db:"total_cpu_usage" json:"totalCpuUsage"` // cpu总占用
  10. // TotalMemoryUsage string `db:"total_memory_usage" json:"totalMemoryUsage"` // 内存总占用
  11. // Top10Process string `db:"top10_process" json:"top10Process"` // cpu占用前十的进程信息
  12. // DeviceNumber string `db:"device_number" json:"deviceNumber"` // cpu占用前十的进程信息
  13. // SocIp string `db:"soc_ip" json:"socIp"` // cpu占用前十的进程信息
  14. //}
  15. // 保存资源占用情况
  16. func SendResourceUsage() {
  17. for {
  18. time.Sleep(time.Duration(2) * time.Second)
  19. responseString, err := util.HttpPostJsonWithHeaders(
  20. CloudConfig.Monitor.Url,
  21. map[string]string{"Authorization": "U9yKpD6kZZDDe4LFKK6myAxBUT1XRrDM"},
  22. map[string]string{
  23. "totalCpuUsage": util.ToString(util.GetCpuPercent()),
  24. "totalMemoryUsage": util.ToString(util.GetMemoryPercent()),
  25. "top10Process": util.ToString(util.GetTop10()),
  26. "deviceNumber": LocalConfig.EquipmentNo,
  27. "socIp": LocalConfig.Node.Ip,
  28. },
  29. )
  30. if err != nil {
  31. c_log.GlobalLogger.Errorf("发送数据监控信息报错%v,响应信息为:%v", err, responseString)
  32. }
  33. c_log.GlobalLogger.Infof("发送数据监控信息成功,响应信息为:%v", responseString)
  34. }
  35. }