Reworked host packets page and removed dscp page

This commit is contained in:
MatteoBiscosi 2022-11-09 16:44:12 +01:00
parent cfbb3306b3
commit 4ed6ae9d8a
10 changed files with 337 additions and 100 deletions

View file

@ -361,12 +361,6 @@ else
page_name = "packets",
label = i18n("packets"),
},
{
hidden = only_historical,
active = page == "DSCP",
page_name = "DSCP",
label = i18n("dscp"),
},
{
hidden = only_historical,
active = page == "ports",
@ -1055,98 +1049,12 @@ else
print("</table>\n")
elseif((page == "packets")) then
print [[
<table class="table table-bordered table-striped">
]]
local tots = 0 for key, value in pairs(host["pktStats.sent"]["size"]) do tots = tots + value end
local totr = 0 for key, value in pairs(host["pktStats.recv"]["size"]) do totr = totr + value end
print('<tr>')
if(tots > 0) then
print('<th class="text-start">'..i18n("packets_page.sent_vs_rcvd_distribution")..'</th>')
print('<td colspan=1><div class="pie-chart" id="sizeSentDistro"></div></td>')
else
print('<th class="text-start" style="width: 15rem;"> '..i18n("packets_page.sent_vs_rcvd_distribution")..'</th>')
print('<td colspan=1 style="width: 15rem;">~</td>')
end
if(totr > 0) then
print('<td colspan=1><div class="pie-chart" id="sizeRecvDistro"></div></td>')
else
print('<td colspan=1 style="width: 15rem;">~</td>')
end
print('</tr>')
local has_tcp_distro = (host["tcp.packets.rcvd"] + host["tcp.packets.sent"] > 0)
local has_arp_distro = (not isEmptyString(host["mac"])) and (host["mac"] ~= "00:00:00:00:00:00") and (ifs.type ~= "zmq")
if(has_tcp_distro and has_arp_distro) then
print('<tr><th class="text-start">'..i18n("packets_page.tcp_flags_vs_arp_distribution")..'</th><td colspan=1><div class="pie-chart" id="flagsDistro"></div></td><td colspan=1><div class="pie-chart" id="arpDistro"></div></td></tr>')
else
if (has_tcp_distro) then
print('<tr><th class="text-start">'..i18n("packets_page.tcp_flags_distribution")..'</th><td colspan=5><div class="pie-chart" id="flagsDistro"></div></td></tr>')
elseif (has_arp_distro) then
if (macinfo ~= nil) and (macinfo["arp_requests.sent"] + macinfo["arp_requests.rcvd"] + macinfo["arp_replies.sent"] + macinfo["arp_replies.rcvd"] > 0) then
print('<tr><th class="text-start">'..i18n("packets_page.arp_distribution")..'</th><td colspan=5><div class="pie-chart" id="arpDistro"></div></td></tr>')
end
else
print('<tr><th class="text-start">'..i18n("packets_page.tcp_flags_distribution")..'</th>') print('<td colspan=5>~</td></tr>')
end
end
hostinfo2json(host_info)
print [[
</table>
<script type='text/javascript'>
window.onload=function() {
do_pie("#sizeSentDistro", ']]
print (ntop.getHttpPrefix())
print [[/lua/host_pkt_distro.lua', { distr: "size", direction: "sent", ifid: "]] print(ifId.."") print ('", '..hostinfo2json(host_info) .."}, \"\", refresh); \n")
print [[
do_pie("#sizeRecvDistro", ']]
print (ntop.getHttpPrefix())
print [[/lua/host_pkt_distro.lua', { distr: "size", direction: "recv", ifid: "]] print(ifId.."") print ('", '..hostinfo2json(host_info) .."}, \"\", refresh); \n")
print [[
do_pie("#flagsDistro", ']]
print (ntop.getHttpPrefix())
print [[/lua/if_tcpflags_pkt_distro.lua', { ifid: "]] print(ifId.."") print ('", '..hostinfo2json(host_info) .."}, \"\", refresh); \n")
-- table.clone needed to change macinfo while keeping host_info unchanged
local macinfo = table.clone(host_info)
macinfo["host"] = host["mac"]
print [[
do_pie("#arpDistro", ']]
print (ntop.getHttpPrefix())
print [[/lua/get_arp_data.lua', { ifid: "]] print(ifId.."") print ('", '..hostinfo2json(macinfo) .."}, \"\", refresh); \n")
print [[
}
</script><p>
]]
elseif((page == "DSCP")) then
print('<table class="table table-bordered table-striped">\n')
print('<tr><th class="text-start">'..i18n("dscp_page.statistics_sent")..'</th><td colspan=5><div class="pie-chart" id="dscpPrecedenceSent"></div></td></tr>')
print('<tr><th class="text-start">'..i18n("dscp_page.statistics_received")..'</th><td colspan=5><div class="pie-chart" id="dscpPrecedenceReceived"></div></td></tr>')
print [[
</table>
<script type='text/javascript'>
window.onload=function() {
do_pie("#dscpPrecedenceSent", ']] print (ntop.getHttpPrefix()) print [[/lua/rest/v2/get/host/dscp/stats.lua', { direction: "sent", ifid: "]] print(ifId.."") print ('", '..hostinfo2json(host_info) .."}, \"\", refresh); \n")
print [[
do_pie("#dscpPrecedenceReceived", ']] print (ntop.getHttpPrefix()) print [[/lua/rest/v2/get/host/dscp/stats.lua', { direction: "recv", ifid: "]] print(ifId.."") print ('", '..hostinfo2json(host_info) .."}, \"\", refresh); \n")
print [[
}
</script>
]]
template.render("pages/hosts/packets_stats.template", {
view = "applications",
host_ip = host_ip,
vlan = host_vlan,
ifid = ifId,
})
elseif((page == "ports")) then
print('<table class="table table-bordered table-striped">\n')
@ -1321,7 +1229,7 @@ else
end
elseif((page == "traffic")) then
-- template render
template.render("pages/hosts/traffic.template", {})
template.render("pages/hosts/traffic_stats.template", {})
elseif((page == "listening_ports")) then
template.render("htmlPages/hostDetails/listening-ports.template", {
@ -1598,7 +1506,6 @@ elseif(page == "flows") then
traffic_type = _GET["traffic_type"],
version = _GET["version"],
l4proto = _GET["l4proto"],
dscp_class = _GET["dscp_class"],
host = hostinfo2hostkey(host),
tskey = _GET["tskey"],
host_pool_id = _GET["host_pool_id"],

View file

@ -0,0 +1,40 @@
--
-- (C) 2013-22 - ntop.org
--
dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
-- Imports
require "lua_utils"
local rest_utils = require "rest_utils"
local graph_utils = require "graph_utils"
-- Local variables
local host_ip = _GET["host"]
local vlan = _GET["vlan"]
local host_stats = interface.getHostInfo(host_ip, vlan) or {}
local rsp = {
labels = {},
series = {},
colors = {},
}
if host_stats then
local eth_stats = interface.getMacInfo(host_stats["mac"])
if eth_stats then
local arp_sent = eth_stats["arp_requests.sent"] + eth_stats["arp_replies.sent"]
local arp_rcvd = eth_stats["arp_requests.rcvd"] + eth_stats["arp_replies.rcvd"]
rsp["labels"][1] = i18n("sent")
rsp["series"][1] = arp_sent
rsp["colors"][1] = graph_utils.get_html_color(1)
rsp["labels"][2] = i18n("received")
rsp["series"][2] = arp_rcvd
rsp["colors"][2] = graph_utils.get_html_color(2)
end
end
rest_utils.answer(rest_utils.consts.success.ok, rsp)

View file

@ -0,0 +1,44 @@
--
-- (C) 2013-22 - ntop.org
--
dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
-- Imports
require "lua_utils"
local rest_utils = require "rest_utils"
local stats_utils = require "stats_utils"
local graph_utils = require "graph_utils"
-- Local variables
local host_ip = _GET["host"]
local vlan = _GET["vlan"]
local host_stats = interface.getHostInfo(host_ip, vlan) or {}
local rsp = {
labels = {},
series = {},
colors = {},
show = true
}
if host_stats and host_stats["pktStats.recv"] then
local serie = {}
local current_data = 0
local data = host_stats["pktStats.recv"]["size"]
for label, value in pairs(data or {}) do
serie[#serie + 1] = { label = label, value = value }
end
local collapsed = stats_utils.collapse_stats(serie, 1, 5 --[[ threshold ]])
for _, value in pairs(collapsed or {}) do
current_data = current_data + 1
rsp["labels"][#rsp["labels"] + 1] = value.label
rsp["series"][#rsp["series"] + 1] = value.value
rsp["colors"][#rsp["colors"] + 1] = graph_utils.get_html_color(current_data)
end
end
rest_utils.answer(rest_utils.consts.success.ok, rsp)

View file

@ -0,0 +1,43 @@
--
-- (C) 2013-22 - ntop.org
--
dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
-- Imports
require "lua_utils"
local rest_utils = require "rest_utils"
local stats_utils = require "stats_utils"
local graph_utils = require "graph_utils"
-- Local variables
local host_ip = _GET["host"]
local vlan = _GET["vlan"]
local host_stats = interface.getHostInfo(host_ip, vlan) or {}
local rsp = {
labels = {},
series = {},
colors = {},
}
if host_stats and host_stats["pktStats.sent"] then
local serie = {}
local current_data = 0
local data = host_stats["pktStats.sent"]["size"]
for label, value in pairs(data or {}) do
serie[#serie + 1] = { label = label, value = value }
end
local collapsed = stats_utils.collapse_stats(serie, 1, 5 --[[ threshold ]])
for _, value in pairs(collapsed or {}) do
current_data = current_data + 1
rsp["labels"][#rsp["labels"] + 1] = value.label
rsp["series"][#rsp["series"] + 1] = value.value
rsp["colors"][#rsp["colors"] + 1] = graph_utils.get_html_color(current_data)
end
end
rest_utils.answer(rest_utils.consts.success.ok, rsp)

View file

@ -0,0 +1,55 @@
--
-- (C) 2013-22 - ntop.org
--
dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
-- Imports
require "lua_utils"
local rest_utils = require "rest_utils"
local graph_utils = require "graph_utils"
-- Local variables
local host_ip = _GET["host"]
local vlan = _GET["vlan"]
local host_stats = interface.getHostInfo(host_ip, vlan) or {}
local current_data = 0
local rsp = {
labels = {},
series = {},
colors = {},
}
local pkt_distribution = {
['syn'] = 'SYN',
['synack'] = 'SYN/ACK',
['finack'] = 'FIN/ACK',
['rst'] = 'RST',
}
if host_stats and host_stats["pktStats.sent"] then
local serie = {}
local current_data = 0
local data = host_stats["pktStats.sent"]["tcp_flags"]
for label, value in pairs(data or {}) do
serie[label] = value
end
data = host_stats["pktStats.recv"]["tcp_flags"]
for label, value in pairs(data or {}) do
serie[label] = serie[label] + value
end
for label, value in pairs(serie or {}) do
current_data = current_data + 1
rsp["labels"][#rsp["labels"] + 1] = pkt_distribution[label]
rsp["series"][#rsp["series"] + 1] = value
rsp["colors"][#rsp["colors"] + 1] = graph_utils.get_html_color(current_data)
end
end
rest_utils.answer(rest_utils.consts.success.ok, rsp)