From aadf62caf021cfb191908bbb44b22246f3b60642 Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Thu, 10 Sep 2020 21:06:16 +0200 Subject: [PATCH] Add total to bandwidth graph --- luci-app-mptcp/luasrc/controller/mptcp.lua | 71 ++++++++++++++++ .../luasrc/view/mptcp/multipath.htm | 83 ++++++++++++++----- 2 files changed, 133 insertions(+), 21 deletions(-) diff --git a/luci-app-mptcp/luasrc/controller/mptcp.lua b/luci-app-mptcp/luasrc/controller/mptcp.lua index df33186e4..38eae6c4e 100644 --- a/luci-app-mptcp/luasrc/controller/mptcp.lua +++ b/luci-app-mptcp/luasrc/controller/mptcp.lua @@ -34,9 +34,27 @@ function interface_bandwidth(iface) end end + +function string.split(input, delimiter) + input = tostring(input) + delimiter = tostring(delimiter) + if (delimiter=='') then return false end + local pos,arr = 0, {} + -- for each divider found + for st,sp in function() return string.find(input, delimiter, pos, true) end do + table.insert(arr, string.sub(input, pos, st - 1)) + pos = sp + 1 + end + table.insert(arr, string.sub(input, pos)) + return arr +end + function multipath_bandwidth() local result = { }; local uci = luci.model.uci.cursor() + local res={ }; + local str=""; + local tmpstr=""; uci:foreach("network", "interface", function(s) local intname = s[".name"] @@ -64,6 +82,59 @@ function multipath_bandwidth() end end) + res["total"]={ }; + for i=1,60 do + res["total"][i]={} + for j=1,5 do + res["total"][i][j]=0 + end + end + + for key,value in pairs(result) do + res[key]={} + value=(string.gsub(value, "^%[%[", "")) + value=(string.gsub(value, "%]%]", "")) + local temp1 = string.split(value, "],") + res[key][1]=temp1[1] + for i=2,60 do + res[key][i]={} + res[key][i]=(string.gsub(temp1[i], "%[", " ")) + end + for i=1,60 do + res[key][i] = string.split(res[key][i], ",") + for j=1,5 do + if "string"== type(res[key][i][j]) then + res[key][i][j]= tonumber(res[key][i][j]) + end + if "string"==type(res["total"][i][j]) then + res["total"][i][j]= tonumber(res["total"][i][j]) + end + if j ==1 then + res["total"][i][j] = res[key][i][j] + else + res["total"][i][j] = res["total"][i][j] + res[key][i][j] + end + end + end + end + for i=1,60 do + for j=1,5 do + if "number"== type(res["total"][i][j]) then + res["total"][i][j]= tostring(res["total"][i][j]) + end + end + end + for i=1,60 do + if i == 60 then + tmpstr = "["..table.concat(res["total"][i], ",") + else + tmpstr = "["..table.concat(res["total"][i], ",").."]," + end + str = str..tmpstr + end + str = "["..str.."]]" + result["total"]=str + luci.http.prepare_content("application/json") luci.http.write_json(result) end diff --git a/luci-app-mptcp/luasrc/view/mptcp/multipath.htm b/luci-app-mptcp/luasrc/view/mptcp/multipath.htm index c8b427cc1..dd4877f40 100644 --- a/luci-app-mptcp/luasrc/view/mptcp/multipath.htm +++ b/luci-app-mptcp/luasrc/view/mptcp/multipath.htm @@ -54,6 +54,8 @@