Merge the LQM info onto the Mesh page (#1095)

This commit is contained in:
Tim Wilkinson 2024-02-09 20:45:52 -08:00 committed by GitHub
parent a810b3b63b
commit 139c5f66e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 156 additions and 25 deletions

View File

@ -1,3 +0,0 @@
if uci.cursor():get("aredn", "@lqm[0]", "enable") == "1" then
return { href = "lqm", display = "Neighbor Status", hint = "See the link status to our neighbors", enable = not config_mode }
end

View File

@ -44,6 +44,7 @@ require("uci")
aredn.info = require("aredn.info")
aredn.olsr = require("aredn.olsr")
require("iwinfo")
require('luci.jsonc')
local html = aredn.html
@ -410,10 +411,10 @@ html.print([[
width: 25%;
}
#nTable th:nth-child(2) {
width: 45%;
width: 50%;
}
#nTable th:nth-child(3) {
width: 30%;
width: 25%;
}
#cTable {
margin-bottom: 12px;
@ -422,20 +423,31 @@ html.print([[
width: 25%;
}
#cTable th:nth-child(2), #rTable th:nth-child(2) {
width: 25%;
}
#cTable th:nth-child(3), #cTable th:nth-child(4) {
width: 6%;
}
#cTable th:nth-child(5) {
width: 8%;
}
#rTable th:nth-child(3) {
width: 20%;
}
#rTable th:nth-child(4) {
#cTable th:nth-child(3), #cTable th:nth-child(4), #cTable th:nth-child(5) {
width: 4%;
padding: 0 2px 0 0;
text-align: right;
}
#cTable th:nth-child(6), #cTable th:nth-child(7), #cTable th:nth-child(8) {
width: 6%;
padding: 0 2px 0 0;
text-align: right;
}
#cTable td:nth-child(3), #cTable td:nth-child(4), #cTable td:nth-child(5), #cTable td:nth-child(6), #cTable td:nth-child(7), #cTable td:nth-child(8) {
text-align: right;
padding: 0 2px 0 0;
}
#cTable th:nth-child(9) {
width: 25%;
}
#rTable th:nth-child(3) {
width: 30%;
}
#rTable th:nth-child(4) {
width: 25%;
}
tr.s.f.nf {
display: table-row;
}
@ -524,7 +536,7 @@ end
html.print("<table id=nTable class=s>")
html.print("<tr class=h>")
html.print("<th width=25%>Node Name</th>")
html.print("<th>Node Name</th>")
html.print("<th>LAN Hostname</th>")
html.print("<th>Service Name</th>")
html.print("</tr>")
@ -620,12 +632,22 @@ html.print("</table>")
-- show current neighbors table
html.print("<table id='cTable' class=s><tr class=h>")
html.print("<th width=25%>Current Neighbors</th>")
html.print("<th>Current Neighbors</th>")
html.print("<th>LAN Hostname</th>")
html.print("<th title='Percent of packets successfully received'>LQ</th><th title='Percent of packets successfully sent'>NLQ</th><th>TxMbps</th>")
html.print("<th title='Percent of packets successfully received'>LQ</th><th title='Percent of packets successfully sent'>NLQ</th>")
html.print("<th>SNR</th><th>Quality</th><th>TxMbps</th><th>Distance</th>")
html.print("<th>Service Name</th>")
html.print("</tr>")
local trackers = {}
local l = io.open("/tmp/lqm.info")
if l then
local lqm = luci.jsonc.parse(l:read("*a"))
l:close()
trackers = lqm.trackers
end
local now = nixio.sysinfo().uptime
local rows = {}
local neighservices = {}
for ip, link in pairs(links)
@ -674,15 +696,68 @@ do
nodeiface = "wan"
end
end
if nodeiface then
c1 = c1 .. " &nbsp; <small>(" .. nodeiface .. ")</small>"
end
local c2 = ""
local c3 = string.format("%.0f%%", math.min(100, math.ceil(100 * link.lq * link.weight)))
local c4 = string.format("%.0f%%", math.min(100, math.ceil(100 * link.nlq * link.weight)))
local c4b = ""
local c4c = ""
local c5 = string.format("%s", link.mbps)
local c5b = ""
local c6 = ""
-- lqm info
local lqmstatus = nil
for _, track in pairs(trackers)
do
if track.ip == ipmain then
if track.hidden or track.blocked then
break
end
if track.pending > now then
lqmstatus = "pending"
elseif track.routable then
lqmstatus = "active"
else
lqmstatus = "idle"
end
if track.snr > 0 then
c4b = track.snr
if track.rev_snr then
c4b = c4b .. "/" .. track.rev_snr
end
end
if track.quality then
c4c = track.quality .. "%"
end
if track.distance then
if true then
local v = track.distance * 0.000621371
if v > 1 then
c5b = math.ceil(v) .. " miles"
elseif v > 0.5 then
c5b = "1 mile"
end
else
c5b = math.ceil(track.distance * 0.001) .. " km"
end
end
break
end
end
if nodeiface then
if lqmstatus then
c1 = c1 .. "&nbsp;<small>(" .. nodeiface .. "," .. lqmstatus .. ")</small>"
else
c1 = c1 .. "&nbsp;<small>(" .. nodeiface .. ")</small>"
end
else
if lqmstatus then
c1 = c1 .. "&nbsp;<small>(" .. lqmstatus .. ")</small>"
end
end
-- print node services if any
if not neighservices[name] then
neighservices[name] = true
@ -719,8 +794,67 @@ do
end
end
-- Build this row
local row = "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='s f'>" .. c2 .. "</td><td>" .. c3 .. "</td><td>" .. c4 .. "</td><td>" .. c5 .. "</td><td class='s f'>" .. c6 .. "</td></tr>"
rows[#rows + 1] = { key = name, row = row }
local row = "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='s f'>" .. c2 .. "</td><td>" .. c3 .. "</td><td>" .. c4 .. "</td><td>" .. c4b .. "</td><td>" .. c4c .. "</td><td>" .. c5 .. "</td><td>" .. c5b .. "</td><td class='s f'>" .. c6 .. "</td></tr>"
rows[#rows + 1] = { key = name:lower(), row = row }
end
for _, track in pairs(trackers)
do
if track.blocked or track.hidden then
local name = track.ip
if track.hostname then
name = track.hostname
end
local c1 = "<a href='http://" .. name:match("(.*%S)%s*$") .. ":8080/'>" .. name .. "</a>"
local c4c = ""
local c4b = ""
local c5b = ""
if track.blocked then
if track.blocks.user then
c1 = c1 .. "&nbsp;<small>(blocked user)</small>"
elseif track.blocks.dtd then
c1 = c1 .. "&nbsp;<small>(blocked dtd)</small>"
elseif track.blocks.distance then
c1 = c1 .. "&nbsp;<small>(blocked distance)</small>"
elseif track.blocks.signal then
c1 = c1 .. "&nbsp;<small>(blocked signal)</small>"
elseif track.blocks.dup then
c1 = c1 .. "&nbsp;<small>(blocked dup)</small>"
elseif track.blocks.quality then
if track.tx_quality < track.ping_quality then
c1 = c1 .. "&nbsp;<small>(blocked retries)</small>"
else
c1 = c1 .. "&nbsp;<small>(blocked latency)</small>"
end
else
c1 = c1 .. "&nbsp;<small>(blocked)</small>"
end
if track.snr > 0 then
c4b = track.snr
if track.rev_snr then
c4b = c4b .. "/" .. track.rev_snr
end
end
if track.quality then
c4c = track.quality .. "%"
end
elseif track.hidden then
c1 = c1 .. "&nbsp;<small>(hidden)</small>"
end
if track.distance then
if true then
local v = track.distance * 0.000621371
if v > 1 then
c5b = math.ceil(v) .. " miles"
elseif v > 0.5 then
c5b = "1 mile"
end
else
c5b = math.ceil(track.distance * 0.001) .. " km"
end
end
local row = "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='s f'></td><td></td><td></td><td>" .. c4b .. "</td><td>" .. c4c .. "</td><td></td><td>" .. c5b .. "</td><td class='s f'></td></tr>"
rows[#rows + 1] = { key = name:lower(), row = row }
end
end
if #rows > 0 then
table.sort(rows, function(a,b) return a.key < b.key end)
@ -790,7 +924,7 @@ html.print("</table>")
-- show remote node table
html.print("<table id='rTable' class=s><tr class=h>")
html.print("<th width=25%>Remote Nodes</th>")
html.print("<th>Remote Nodes</th>")
html.print("<th>LAN Hostname</th>")
html.print("<th>ETX</th>")
html.print("<th>Service Name</th>")
@ -894,7 +1028,7 @@ do
end
-- Build this row
local row = "<tr class=s><td class='s f'>" .. c1 .. "</td><td class='s f'>" .. c2 .. "</td><td>" .. c3 .. "</td><td class='s f'>" .. c4 .. "</td></tr>"
rows[#rows + 1] = { key = string.format("%05d/%s", math.floor(100 * host.etx), host.name), row = row }
rows[#rows + 1] = { key = string.format("%05d/%s", math.floor(100 * host.etx), host.name:lower()), row = row }
end
end
end