1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00
This commit is contained in:
suyuan 2020-11-12 21:13:58 +08:00
parent 7cd0b20e22
commit 9740e28234
3 changed files with 202 additions and 74 deletions

View file

@ -296,7 +296,7 @@ Thanks :)*/
.network-node .info .title i { .network-node .info .title i {
font-weight: lighter; font-weight: lighter;
font-size: 0.8em; font-size: 1em;
text-transform: uppercase; text-transform: uppercase;
} }

View file

@ -269,40 +269,131 @@ function interface_bandwidth(iface)
end end
end end
function multipath_bandwidth() function string.split(input, delimiter)
local result = { }; input = tostring(input)
local uci = luci.model.uci.cursor() delimiter = tostring(delimiter)
if (delimiter=='') then return false end
uci:foreach("network", "interface", function(s) local pos,arr = 0, {}
local intname = s[".name"] -- for each divider found
local dev = get_device(intname) for st,sp in function() return string.find(input, delimiter, pos, true) end do
if dev == "" then table.insert(arr, string.sub(input, pos, st - 1))
dev = get_device(s["ifname"]) pos = sp + 1
end end
local multipath = s["multipath"] or "" table.insert(arr, string.sub(input, pos))
if dev ~= "lo" and dev ~= "" then return arr
if multipath == "" then
multipath = uci:get("openmptcprouter", intname, "multipath") or ""
end
if multipath == "" then
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 ""
if bwc ~= nil then
--result[dev] = "[" .. string.gsub(bwc, '[\r\n]', '') .. "]"
result[intname] = "[" .. string.gsub(bwc, '[\r\n]', '') .. "]"
else
result[dev] = "[]"
end
end
end
end)
luci.http.prepare_content("application/json")
luci.http.write_json(result)
end 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"])
end
local multipath = s["multipath"] or ""
if dev ~= "lo" and dev ~= "" then
if multipath == "" then
multipath = uci:get("openmptcprouter", intname, "multipath") or ""
end
if multipath == "" then
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]', '') .. "]"
if label ~= nil then
result[intname .. " (" .. label .. ")" ] = "[" .. string.gsub(bwc, '[\r\n]', '') .. "]"
else
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) function get_device(interface)
local dump = require("luci.util").ubus("network.interface.%s" % interface, "status", {}) local dump = require("luci.util").ubus("network.interface.%s" % interface, "status", {})
if dump ~= nil then if dump ~= nil then

View file

@ -1,5 +1,5 @@
<% <%
-- Copyright 2015 OVH1 (OverTheBox@ovh.net) -- Copyright 2015 OVH (OverTheBox@ovh.net)
-- Simon Lelievre (simon.lelievre@corp.ovh.com) -- Simon Lelievre (simon.lelievre@corp.ovh.com)
-- Sebastien Duponcheel (sebastien.duponcheel@ovh.net) -- Sebastien Duponcheel (sebastien.duponcheel@ovh.net)
-- --
@ -19,7 +19,7 @@
-- along with OverTheBox. If not, see (http://www.gnu.org/licenses/) -- 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 -- Small changes to make this work with OpenMPTCProuter
-- New features: -- New features:
@ -55,6 +55,8 @@
end end
local curifname = luci.http.formvalue("dev") or "all" local curifname = luci.http.formvalue("dev") or "all"
local bandwidthtotalurl = "admin/system/status/multipath_bandwidth"
local bandwidthintfurl = "admin/system/status/interface_bandwidth"
-%> -%>
<%+header%> <%+header%>
<link rel="stylesheet" type="text/css" href="<%=resource%>/status/css/wanstatus.css?v=git-20"/> <link rel="stylesheet" type="text/css" href="<%=resource%>/status/css/wanstatus.css?v=git-20"/>
@ -789,21 +791,23 @@
<script type="text/javascript">//<![CDATA[ <script type="text/javascript">//<![CDATA[
function stringToColour(str) { function stringToColour(str) {
if(str == "wan") if(str == "total")
return "OrangeRed";
if(str.substring(0, 4) == "wan")
return "FireBrick"; return "FireBrick";
if(str == "wan1") if(str.substring(0, 4) == "wan1")
return "DeepSkyBlue"; return "DeepSkyBlue";
if(str == "wan2") if(str.substring(0, 4) == "wan2")
return "SeaGreen"; return "SeaGreen";
if(str == "wan3") if(str.substring(0, 4) == "wan3")
return "PaleGreen"; return "PaleGreen";
if(str == "wan4") if(str.substring(0, 4) == "wan4")
return "PowderBlue"; return "PowderBlue";
if(str == "wan5") if(str.substring(0, 4) == "wan5")
return "Salmon"; return "Salmon";
if(str == "wan6") if(str.substring(0, 4) == "wan6")
return "LightGreen"; return "LightGreen";
if(str == "wan7") if(str.substring(0, 4) == "wan7")
return "PaleTurquoise"; return "PaleTurquoise";
// Generate a color folowing the name // Generate a color folowing the name
Math.seedrandom(str); Math.seedrandom(str);
@ -920,13 +924,6 @@
height = dnsvg.offsetHeight - 2; height = dnsvg.offsetHeight - 2;
data_wanted = Math.ceil(width / step); data_wanted = Math.ceil(width / step);
/* prefill datasets
for (var i = 0; i < data_wanted; i++)
{
data_tx[i] = 0;
}
*/
/* find svg elements */ /* find svg elements */
labeldn_25 = Gdn.getElementById('label_25'); labeldn_25 = Gdn.getElementById('label_25');
labeldn_50 = Gdn.getElementById('label_50'); 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); labelup_scale.innerHTML = String.format('<%:(%d minutes window, %d seconds interval)%>', 3, data_wanted / 60);
/* render datasets, start update interval */ /* 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) function(x, dataarray)
{ {
var data_max_dnl = 0; var data_max_dnl = 0;
@ -994,6 +991,7 @@
var data_tx_peak = 0; var data_tx_peak = 0;
var data = {}; var data = {};
var pre_itf = "";
for(var itf in dataarray) for(var itf in dataarray)
{ {
@ -1006,7 +1004,15 @@
// Create a new polygon to draw the bandwith // Create a new polygon to draw the bandwith
var dnline = Gdn.createElementNS('http://www.w3.org/2000/svg', 'polyline'); var dnline = Gdn.createElementNS('http://www.w3.org/2000/svg', 'polyline');
dnline.setAttributeNS(null, 'id', 'rx_' + itf); dnline.setAttributeNS(null, 'id', 'rx_' + itf);
dnline.setAttributeNS(null, 'style', 'fill:' + color + ';fill-opacity:0.4;stroke:black;stroke-width:0.1'); 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); Gdn.getElementById('rx').parentNode.appendChild(dnline);
dnPolygons[itf] = Gdn.getElementById('rx_' + itf); dnPolygons[itf] = Gdn.getElementById('rx_' + itf);
@ -1019,11 +1025,18 @@
// Create legend for this connextion // Create legend for this connextion
var table = document.getElementById('download_stats'); var table = document.getElementById('download_stats');
var tr = table.insertRow(); if (pre_itf == "total")
{
var tr = table.insertRow(0);
}
else
{
var tr = table.insertRow();
}
tr.setAttribute('id', itf + '_download'); tr.setAttribute('id', itf + '_download');
// Create cells of the table // Create cells of the table
var itflabel = tr.insertCell(0); var itflabel = tr.insertCell(0);
// Crete itf legend // Create itf legend
var strong = document.createElement('strong') var strong = document.createElement('strong')
strong.appendChild(document.createTextNode(itf)); strong.appendChild(document.createTextNode(itf));
strong.setAttribute('style', 'border-bottom:2px solid ' + color); strong.setAttribute('style', 'border-bottom:2px solid ' + color);
@ -1047,7 +1060,15 @@
{ {
var upline = Gup.createElementNS('http://www.w3.org/2000/svg', 'polyline'); var upline = Gup.createElementNS('http://www.w3.org/2000/svg', 'polyline');
upline.setAttributeNS(null, 'id', 'tx_' + itf); upline.setAttributeNS(null, 'id', 'tx_' + itf);
upline.setAttributeNS(null, 'style', 'fill:' + color + ';fill-opacity:0.4;stroke:black;stroke-width:0.1'); 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); Gup.getElementById('tx').parentNode.appendChild(upline);
upPolygons[itf] = Gup.getElementById('tx_' + itf); upPolygons[itf] = Gup.getElementById('tx_' + itf);
@ -1060,7 +1081,16 @@
// Create legend for this connextion // Create legend for this connextion
var table = document.getElementById('upload_stats'); var table = document.getElementById('upload_stats');
var tr = table.insertRow();
if (pre_itf == "total")
{
var tr = table.insertRow(0);
}
else
{
var tr = table.insertRow();
}
tr.setAttribute('id', itf + '_upload'); tr.setAttribute('id', itf + '_upload');
// Create cells of the table // Create cells of the table
var itflabel = tr.insertCell(0); var itflabel = tr.insertCell(0);
@ -1082,8 +1112,8 @@
var itfpeak = tr.insertCell(6); var itfpeak = tr.insertCell(6);
itfpeak.setAttribute('id', itf + '_upload_peak'); itfpeak.setAttribute('id', itf + '_upload_peak');
itfpeak.appendChild(document.createTextNode('0 <%:kbit/s%> (0 <%:kB/s%>)')); itfpeak.appendChild(document.createTextNode('0 <%:kbit/s%> (0 <%:kB/s%>)'));
} }
if (pre_itf != "total") pre_itf = itf;
} }
var dnsma = {}; var dnsma = {};
@ -1137,6 +1167,7 @@
var toadditf = [ ]; var toadditf = [ ];
for (var itf in data) for (var itf in data)
{ {
//if (itf == "total") continue;
uplineDnl[itf] = [ ]; uplineDnl[itf] = [ ];
downlineDnl[itf]= [ ]; downlineDnl[itf]= [ ];
uplineUpl[itf] = [ ]; uplineUpl[itf] = [ ];
@ -1150,11 +1181,15 @@
{ {
var rx_bot=0; var rx_bot=0;
var tx_bot=0; var tx_bot=0;
if (itf != "total")
{
for(var j=0; j < toadditf.length; j++) for(var j=0; j < toadditf.length; j++)
{ {
if (toadditf[j] == "total") continue;
rx_bot += dndata[toadditf[j]][i]; rx_bot += dndata[toadditf[j]][i];
tx_bot += updata[toadditf[j]][i]; tx_bot += updata[toadditf[j]][i];
} }
}
// set upline of the interface // set upline of the interface
uplineDnl[itf][i] = dndata[itf][i] + rx_bot; uplineDnl[itf][i] = dndata[itf][i] + rx_bot;
data_rx_peak = Math.max(data_rx_peak, dndata[itf][i]); data_rx_peak = Math.max(data_rx_peak, dndata[itf][i]);
@ -1174,11 +1209,14 @@
} }
if(toadditf.length) if(toadditf.length)
{ {
if (toadditf[toadditf.length-1] != "total")
{
downlineDnl[itf][i] = uplineDnl[toadditf[toadditf.length-1]][i]; downlineDnl[itf][i] = uplineDnl[toadditf[toadditf.length-1]][i];
downlineUpl[itf][i] = uplineUpl[toadditf[toadditf.length-1]][i]; downlineUpl[itf][i] = uplineUpl[toadditf[toadditf.length-1]][i];
}
} }
}
}
toadditf.push(itf); toadditf.push(itf);
// Update stats labels // Update stats labels
@ -1216,6 +1254,7 @@
for (var itf in uplineDnl) for (var itf in uplineDnl)
{ {
if (itf == "total") continue;
var y_rx = 0; var y_rx = 0;
var y_tx = 0; var y_tx = 0;
@ -1286,7 +1325,7 @@
if (typeof dntopline != "object") if (typeof dntopline != "object")
{ {
dntopline = Gdn.getElementById('rx'); 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 */ /* Move line on top */
var father = dntopline.parentNode; var father = dntopline.parentNode;
father.removeChild(dntopline); father.removeChild(dntopline);
@ -1295,28 +1334,26 @@
if (typeof uptopline != "object") if (typeof uptopline != "object")
{ {
uptopline = Gup.getElementById('tx'); 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 */ /* Move line on top */
var father = uptopline.parentNode; var father = uptopline.parentNode;
father.removeChild(uptopline); father.removeChild(uptopline);
father.appendChild(uptopline); father.appendChild(uptopline);
} }
var y_rx = 0; var y_rx = 0;
var y_tx = 0; var y_tx = 0;
/* plot data */ /* plot data */
var pt_rx = '0,' + height; var pt_rx = '0,' + height;
var pt_tx = '0,' + height; var pt_tx = '0,' + height;
// draw polygon // draw polygon
for (var i = 0; i < uplineDnl[itf].length; i++) for (var i = 0; i < uplineDnl[itf].length; i++)
{ {
var x = i * step; var x = i * step;
y_rx = height - Math.floor((uplineDnl[itf][i]) * data_scale_dnl);
y_rx = height - Math.floor((uplineDnl[itf][i]) * data_scale_dnl); y_tx = height - Math.floor((uplineUpl[itf][i]) * data_scale_upl);
y_tx = height - Math.floor((uplineUpl[itf][i]) * data_scale_upl); pt_rx += ' ' + x + ',' + y_rx;
pt_rx += ' ' + x + ',' + y_rx;
pt_tx += ' ' + x + ',' + y_tx; pt_tx += ' ' + x + ',' + y_tx;
} }
// draw last tangant point in upline graph // draw last tangant point in upline graph
@ -1472,7 +1509,7 @@
label_scale.innerHTML = String.format('<%:(%d minute window, %d second interval)%>', data_wanted / 60, 3); label_scale.innerHTML = String.format('<%:(%d minute window, %d second interval)%>', data_wanted / 60, 3);
/* render datasets, start update interval */ /* 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) function(x, data)
{ {
var data_max = 0; var data_max = 0;