mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
fixbug
This commit is contained in:
parent
7cd0b20e22
commit
9740e28234
3 changed files with 202 additions and 74 deletions
|
@ -296,7 +296,7 @@ Thanks :)*/
|
|||
|
||||
.network-node .info .title i {
|
||||
font-weight: lighter;
|
||||
font-size: 0.8em;
|
||||
font-size: 1em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
|
|
|
@ -269,12 +269,30 @@ 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"]
|
||||
local label = s["label"]
|
||||
local dev = get_device(intname)
|
||||
if dev == "" then
|
||||
dev = get_device(s["ifname"])
|
||||
|
@ -288,21 +306,94 @@ function multipath_bandwidth()
|
|||
multipath = "off"
|
||||
end
|
||||
if multipath == "on" or multipath == "master" or multipath == "backup" or multipath == "handover" then
|
||||
local bwc = luci.sys.exec("luci-bwc -i %q 2>/dev/null" % dev) or ""
|
||||
local bwc = luci.sys.exec("luci-bwc -i %q 2>/dev/null" % dev) or ""
|
||||
if bwc ~= nil then
|
||||
--result[dev] = "[" .. string.gsub(bwc, '[\r\n]', '') .. "]"
|
||||
result[intname] = "[" .. string.gsub(bwc, '[\r\n]', '') .. "]"
|
||||
if label ~= nil then
|
||||
result[intname .. " (" .. label .. ")" ] = "[" .. string.gsub(bwc, '[\r\n]', '') .. "]"
|
||||
else
|
||||
result[dev] = "[]"
|
||||
result[intname] = "[" .. string.gsub(bwc, '[\r\n]', '') .. "]"
|
||||
end
|
||||
else
|
||||
if label ~= nil then
|
||||
result[intname .. " (" .. label .. ")" ] = "[]"
|
||||
else
|
||||
result[intname] = "[]"
|
||||
end
|
||||
end
|
||||
end
|
||||
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, "],")
|
||||
if temp1[2] ~= nil then
|
||||
res[key][1]=temp1[1]
|
||||
for i=2,60 do
|
||||
res[key][i]={}
|
||||
if temp1[i] ~= nil then
|
||||
res[key][i]=(string.gsub(temp1[i], "%[", " "))
|
||||
end
|
||||
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
|
||||
if res[key][i][j] ~= nil then
|
||||
res["total"][i][j] = res[key][i][j]
|
||||
else
|
||||
res["total"][i][j] = 0
|
||||
end
|
||||
else
|
||||
if res[key][i][j] ~= nil then
|
||||
res["total"][i][j] = res["total"][i][j] + res[key][i][j]
|
||||
end
|
||||
end
|
||||
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
|
||||
|
||||
|
||||
function get_device(interface)
|
||||
local dump = require("luci.util").ubus("network.interface.%s" % interface, "status", {})
|
||||
if dump ~= nil then
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<%
|
||||
-- Copyright 2015 OVH1 (OverTheBox@ovh.net)
|
||||
-- Copyright 2015 OVH (OverTheBox@ovh.net)
|
||||
-- Simon Lelievre (simon.lelievre@corp.ovh.com)
|
||||
-- Sebastien Duponcheel (sebastien.duponcheel@ovh.net)
|
||||
--
|
||||
|
@ -19,7 +19,7 @@
|
|||
-- along with OverTheBox. If not, see (http://www.gnu.org/licenses/)
|
||||
-%>
|
||||
<%
|
||||
-- Copyright 2018 Ycarus (Yannick Chabanois) ycarus@zugaina.org
|
||||
-- Copyright 2018-2020 Ycarus (Yannick Chabanois) ycarus@zugaina.org
|
||||
--
|
||||
-- Small changes to make this work with OpenMPTCProuter
|
||||
-- New features:
|
||||
|
@ -55,6 +55,8 @@
|
|||
end
|
||||
|
||||
local curifname = luci.http.formvalue("dev") or "all"
|
||||
local bandwidthtotalurl = "admin/system/status/multipath_bandwidth"
|
||||
local bandwidthintfurl = "admin/system/status/interface_bandwidth"
|
||||
-%>
|
||||
<%+header%>
|
||||
<link rel="stylesheet" type="text/css" href="<%=resource%>/status/css/wanstatus.css?v=git-20"/>
|
||||
|
@ -789,21 +791,23 @@
|
|||
<script type="text/javascript">//<![CDATA[
|
||||
|
||||
function stringToColour(str) {
|
||||
if(str == "wan")
|
||||
if(str == "total")
|
||||
return "OrangeRed";
|
||||
if(str.substring(0, 4) == "wan")
|
||||
return "FireBrick";
|
||||
if(str == "wan1")
|
||||
if(str.substring(0, 4) == "wan1")
|
||||
return "DeepSkyBlue";
|
||||
if(str == "wan2")
|
||||
if(str.substring(0, 4) == "wan2")
|
||||
return "SeaGreen";
|
||||
if(str == "wan3")
|
||||
if(str.substring(0, 4) == "wan3")
|
||||
return "PaleGreen";
|
||||
if(str == "wan4")
|
||||
if(str.substring(0, 4) == "wan4")
|
||||
return "PowderBlue";
|
||||
if(str == "wan5")
|
||||
if(str.substring(0, 4) == "wan5")
|
||||
return "Salmon";
|
||||
if(str == "wan6")
|
||||
if(str.substring(0, 4) == "wan6")
|
||||
return "LightGreen";
|
||||
if(str == "wan7")
|
||||
if(str.substring(0, 4) == "wan7")
|
||||
return "PaleTurquoise";
|
||||
// Generate a color folowing the name
|
||||
Math.seedrandom(str);
|
||||
|
@ -920,13 +924,6 @@
|
|||
height = dnsvg.offsetHeight - 2;
|
||||
data_wanted = Math.ceil(width / step);
|
||||
|
||||
/* prefill datasets
|
||||
for (var i = 0; i < data_wanted; i++)
|
||||
{
|
||||
data_tx[i] = 0;
|
||||
}
|
||||
*/
|
||||
|
||||
/* find svg elements */
|
||||
labeldn_25 = Gdn.getElementById('label_25');
|
||||
labeldn_50 = Gdn.getElementById('label_50');
|
||||
|
@ -979,7 +976,7 @@
|
|||
labelup_scale.innerHTML = String.format('<%:(%d minutes window, %d seconds interval)%>', 3, data_wanted / 60);
|
||||
|
||||
/* render datasets, start update interval */
|
||||
XHR.poll(3, '<%=build_url("admin/system/status/multipath_bandwidth", all)%>', null,
|
||||
XHR.poll(3, '<%=build_url(bandwidthtotalurl, all)%>', null,
|
||||
function(x, dataarray)
|
||||
{
|
||||
var data_max_dnl = 0;
|
||||
|
@ -994,6 +991,7 @@
|
|||
var data_tx_peak = 0;
|
||||
|
||||
var data = {};
|
||||
var pre_itf = "";
|
||||
|
||||
for(var itf in dataarray)
|
||||
{
|
||||
|
@ -1006,7 +1004,15 @@
|
|||
// Create a new polygon to draw the bandwith
|
||||
var dnline = Gdn.createElementNS('http://www.w3.org/2000/svg', 'polyline');
|
||||
dnline.setAttributeNS(null, 'id', 'rx_' + itf);
|
||||
if (itf != "total")
|
||||
{
|
||||
dnline.setAttributeNS(null, 'style', 'fill:' + color + ';fill-opacity:0.4;stroke:black;stroke-width:0.1');
|
||||
}
|
||||
else
|
||||
{
|
||||
//dnline.setAttributeNS(null, 'style', 'fill: none;stroke:OrangeRed;stroke-width:1');
|
||||
dnline.setAttributeNS(null, 'style', 'fill: none;stroke:none');
|
||||
}
|
||||
Gdn.getElementById('rx').parentNode.appendChild(dnline);
|
||||
|
||||
dnPolygons[itf] = Gdn.getElementById('rx_' + itf);
|
||||
|
@ -1019,11 +1025,18 @@
|
|||
|
||||
// Create legend for this connextion
|
||||
var table = document.getElementById('download_stats');
|
||||
if (pre_itf == "total")
|
||||
{
|
||||
var tr = table.insertRow(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
var tr = table.insertRow();
|
||||
}
|
||||
tr.setAttribute('id', itf + '_download');
|
||||
// Create cells of the table
|
||||
var itflabel = tr.insertCell(0);
|
||||
// Crete itf legend
|
||||
// Create itf legend
|
||||
var strong = document.createElement('strong')
|
||||
strong.appendChild(document.createTextNode(itf));
|
||||
strong.setAttribute('style', 'border-bottom:2px solid ' + color);
|
||||
|
@ -1047,7 +1060,15 @@
|
|||
{
|
||||
var upline = Gup.createElementNS('http://www.w3.org/2000/svg', 'polyline');
|
||||
upline.setAttributeNS(null, 'id', 'tx_' + itf);
|
||||
if (itf != "total")
|
||||
{
|
||||
upline.setAttributeNS(null, 'style', 'fill:' + color + ';fill-opacity:0.4;stroke:black;stroke-width:0.1');
|
||||
}
|
||||
else
|
||||
{
|
||||
//upline.setAttributeNS(null, 'style', 'fill:none;stroke:OrangeRed;stroke-width:1');
|
||||
upline.setAttributeNS(null, 'style', 'fill:none;stroke:none');
|
||||
}
|
||||
Gup.getElementById('tx').parentNode.appendChild(upline);
|
||||
|
||||
upPolygons[itf] = Gup.getElementById('tx_' + itf);
|
||||
|
@ -1060,7 +1081,16 @@
|
|||
|
||||
// Create legend for this connextion
|
||||
var table = document.getElementById('upload_stats');
|
||||
|
||||
if (pre_itf == "total")
|
||||
{
|
||||
var tr = table.insertRow(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var tr = table.insertRow();
|
||||
}
|
||||
tr.setAttribute('id', itf + '_upload');
|
||||
// Create cells of the table
|
||||
var itflabel = tr.insertCell(0);
|
||||
|
@ -1082,8 +1112,8 @@
|
|||
var itfpeak = tr.insertCell(6);
|
||||
itfpeak.setAttribute('id', itf + '_upload_peak');
|
||||
itfpeak.appendChild(document.createTextNode('0 <%:kbit/s%> (0 <%:kB/s%>)'));
|
||||
|
||||
}
|
||||
if (pre_itf != "total") pre_itf = itf;
|
||||
}
|
||||
|
||||
var dnsma = {};
|
||||
|
@ -1137,6 +1167,7 @@
|
|||
var toadditf = [ ];
|
||||
for (var itf in data)
|
||||
{
|
||||
//if (itf == "total") continue;
|
||||
uplineDnl[itf] = [ ];
|
||||
downlineDnl[itf]= [ ];
|
||||
uplineUpl[itf] = [ ];
|
||||
|
@ -1150,11 +1181,15 @@
|
|||
{
|
||||
var rx_bot=0;
|
||||
var tx_bot=0;
|
||||
if (itf != "total")
|
||||
{
|
||||
for(var j=0; j < toadditf.length; j++)
|
||||
{
|
||||
if (toadditf[j] == "total") continue;
|
||||
rx_bot += dndata[toadditf[j]][i];
|
||||
tx_bot += updata[toadditf[j]][i];
|
||||
}
|
||||
}
|
||||
// set upline of the interface
|
||||
uplineDnl[itf][i] = dndata[itf][i] + rx_bot;
|
||||
data_rx_peak = Math.max(data_rx_peak, dndata[itf][i]);
|
||||
|
@ -1173,12 +1208,15 @@
|
|||
data_tx_avg = updata[itf][i];
|
||||
}
|
||||
if(toadditf.length)
|
||||
{
|
||||
if (toadditf[toadditf.length-1] != "total")
|
||||
{
|
||||
downlineDnl[itf][i] = uplineDnl[toadditf[toadditf.length-1]][i];
|
||||
downlineUpl[itf][i] = uplineUpl[toadditf[toadditf.length-1]][i];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
toadditf.push(itf);
|
||||
|
||||
// Update stats labels
|
||||
|
@ -1216,6 +1254,7 @@
|
|||
|
||||
for (var itf in uplineDnl)
|
||||
{
|
||||
if (itf == "total") continue;
|
||||
var y_rx = 0;
|
||||
var y_tx = 0;
|
||||
|
||||
|
@ -1286,7 +1325,7 @@
|
|||
if (typeof dntopline != "object")
|
||||
{
|
||||
dntopline = Gdn.getElementById('rx');
|
||||
dntopline.setAttributeNS(null, 'style', 'stroke:DimGray;stroke-width:1;stroke-linecap="round";fill:;fill-opacity:0;');
|
||||
dntopline.setAttributeNS(null, 'style', 'stroke:DimGray;stroke-width:0;stroke-linecap="round";fill:;fill-opacity:0;');
|
||||
/* Move line on top */
|
||||
var father = dntopline.parentNode;
|
||||
father.removeChild(dntopline);
|
||||
|
@ -1295,7 +1334,7 @@
|
|||
if (typeof uptopline != "object")
|
||||
{
|
||||
uptopline = Gup.getElementById('tx');
|
||||
uptopline.setAttributeNS(null, 'style', 'stroke:DimGray;stroke-width:1;stroke-linecap="round";fill:;fill-opacity:0;');
|
||||
uptopline.setAttributeNS(null, 'style', 'stroke:DimGray;stroke-width:0;stroke-linecap="round";fill:;fill-opacity:0;');
|
||||
/* Move line on top */
|
||||
var father = uptopline.parentNode;
|
||||
father.removeChild(uptopline);
|
||||
|
@ -1312,10 +1351,8 @@
|
|||
for (var i = 0; i < uplineDnl[itf].length; i++)
|
||||
{
|
||||
var x = i * step;
|
||||
|
||||
y_rx = height - Math.floor((uplineDnl[itf][i]) * data_scale_dnl);
|
||||
y_tx = height - Math.floor((uplineUpl[itf][i]) * data_scale_upl);
|
||||
|
||||
pt_rx += ' ' + x + ',' + y_rx;
|
||||
pt_tx += ' ' + x + ',' + y_tx;
|
||||
}
|
||||
|
@ -1472,7 +1509,7 @@
|
|||
label_scale.innerHTML = String.format('<%:(%d minute window, %d second interval)%>', data_wanted / 60, 3);
|
||||
|
||||
/* render datasets, start update interval */
|
||||
XHR.poll(3, '<%=build_url("admin/system/status/interface_bandwidth", curifname)%>', null,
|
||||
XHR.poll(3, '<%=build_url(bandwidthintfurl, curifname)%>', null,
|
||||
function(x, data)
|
||||
{
|
||||
var data_max = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue