Posted to tcl by cjo at Fri Sep 08 20:04:43 GMT 2017view pretty
proc ::datastream::request::req_heartbeat { json } { package require unix_serialize json set json localTimestamp [json new number [clock milliseconds]] if { [info commands ::datastream::ws_session] ne {} } { set total_heartbeats [::datastream::ws_session total_heartbeats] if { $total_heartbeats ne {} && $total_heartbeats > 2 } { set uptime [unix get uptime] set procstat [unix serialize procstat] set meminfo [unix serialize meminfo total free buffers cached] set loadavg [unix serialize loadavg] json set json system [json template { { "uptime": { "items": { "procUptime": "~S:uptime" } }, "cpu": { "items": "~J:procstat" }, "memory": { "items": "~J:meminfo" }, "load": { "procLoadAvg": "~J:loadavg" } } }] set lan_ip [::dashos::lan_ip] json set json network [json template { { "lanIP": "~S:lan_ip" } }] } else { set uptime [unix get uptime] json set json system [json template { { "heartbeat_uptime": { "uptime": { "items": { "procUptime": "~S:uptime" } } } } }] } } return $json } # $json has some existing contents that we want to add to set json [::datastream::request::req_heartbeat $json]