hangup_jitterbuffer_metrics.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. local https = require("socket.http")
  2. local ip = os.getenv("LOCAL_IPV4")
  3. local response_body = {}
  4. -- jitter buffer stats
  5. local size_max_ms = session:getVariable("rtp_jb_size_max_ms");
  6. local size_est_ms = session:getVariable("rtp_jb_size_est_ms");
  7. local acceleration_ms = session:getVariable("rtp_jb_acceleration_ms");
  8. local expand_ms = session:getVariable("rtp_jb_expand_ms");
  9. local jitter_max_ms = session:getVariable("rtp_jb_jitter_max_ms");
  10. local jitter_est_ms = session:getVariable("rtp_jb_jitter_est_ms");
  11. local reset_count = session:getVariable("rtp_jb_reset_count");
  12. local reset_too_big = session:getVariable("rtp_jb_reset_too_big");
  13. local reset_missing_frames = session:getVariable("rtp_jb_reset_missing_frames");
  14. local reset_ts_jump = session:getVariable("rtp_jb_reset_ts_jump");
  15. local reset_error = session:getVariable("rtp_jb_reset_error");
  16. local call_id = session:getVariable("sip_call_id");
  17. local out_call_id = session:getVariable("last_bridge_to");
  18. if size_max_ms == nil or size_est_ms == nil or acceleration_ms == nil or expand_ms == nil or jitter_max_ms == nil or jitter_est_ms == nil then
  19. session:consoleLog("info", "[metrics] jitter no data\n");
  20. return
  21. end
  22. local request_body = '{"in_call_id": "'..call_id..'", "out_call_id": "'..out_call_id..'", "jb":{"size_max_ms":'..size_max_ms..
  23. ',"size_est_ms":'..size_est_ms..',"acceleration_ms":'..acceleration_ms..',"expand_ms":'..expand_ms..
  24. ',"jitter_max_ms":'..jitter_max_ms..',"jitter_est_ms":'..jitter_est_ms..',"reset":'..reset_count
  25. -- if reset_too_big ~= "0" then
  26. request_body = request_body .. ',"reset_too_big":'..reset_too_big
  27. -- end
  28. if reset_missing_frames ~= "0" then
  29. request_body = request_body .. ',"reset_missing_frames":'..reset_missing_frames
  30. end
  31. if reset_ts_jump ~= "0" then
  32. request_body = request_body .. ',"reset_ts_jump":'..reset_ts_jump
  33. end
  34. if reset_error ~= "0" then
  35. request_body = request_body .. ',"reset_error":'..reset_error
  36. end
  37. local v = request_body .. '}}';
  38. local r, c, h, s = https.request{
  39. method = 'POST',
  40. url = "http://"..ip..":80/freeswitch_metrics",
  41. headers = {
  42. ["Content-Type"] = "application/json",
  43. ["Content-Length"] = string.len(v)
  44. },
  45. source = ltn12.source.string(v),
  46. sink = ltn12.sink.table(response_body)
  47. }
  48. -- print('statusCode ', c)
  49. session:consoleLog("info", "[metrics] jitter:".. v .. "\n");