Posted to tcl by cjo at Fri Sep 08 20:04:43 GMT 2017view raw

  1. proc ::datastream::request::req_heartbeat { json } {
  2. package require unix_serialize
  3. json set json localTimestamp [json new number [clock milliseconds]]
  4.  
  5. if { [info commands ::datastream::ws_session] ne {} } {
  6. set total_heartbeats [::datastream::ws_session total_heartbeats]
  7. if { $total_heartbeats ne {} && $total_heartbeats > 2 } {
  8. set uptime [unix get uptime]
  9. set procstat [unix serialize procstat]
  10. set meminfo [unix serialize meminfo total free buffers cached]
  11. set loadavg [unix serialize loadavg]
  12. json set json system [json template {
  13. {
  14. "uptime": {
  15. "items": {
  16. "procUptime": "~S:uptime"
  17. }
  18. },
  19. "cpu": {
  20. "items": "~J:procstat"
  21. },
  22. "memory": {
  23. "items": "~J:meminfo"
  24. },
  25. "load": {
  26. "procLoadAvg": "~J:loadavg"
  27. }
  28. }
  29. }]
  30.  
  31. set lan_ip [::dashos::lan_ip]
  32. json set json network [json template {
  33. {
  34. "lanIP": "~S:lan_ip"
  35. }
  36. }]
  37. } else {
  38. set uptime [unix get uptime]
  39. json set json system [json template {
  40. {
  41. "heartbeat_uptime": {
  42. "uptime": {
  43. "items": {
  44. "procUptime": "~S:uptime"
  45. }
  46. }
  47. }
  48. }
  49. }]
  50. }
  51. }
  52.  
  53. return $json
  54. }
  55.  
  56.  
  57. # $json has some existing contents that we want to add to
  58. set json [::datastream::request::req_heartbeat $json]