Replace getFlowPeers function with getFlows and limit results to reduce memory footprint.

This commit is contained in:
emanuele-f 2017-01-25 16:23:47 +01:00 committed by Simone Mainardi
parent 096db1085d
commit 1598598c47
12 changed files with 61 additions and 578 deletions

View file

@ -11,15 +11,16 @@ local json = require("dkjson")
sendHTTPHeader('application/json')
interface.select(ifname)
local max_num_peers = 10
local host_info = url2hostinfo(_GET)
local flows = interface.getFlowPeers(host_info["host"],host_info["vlan"])
local flows = getTopFlowPeers(host2name(host_info["host"], host_info["vlan"]), max_num_peers)
local tot = 0
local peers = {}
local peers_proto = {}
local ndpi = {}
for _, flow in pairs(flows) do
for _, flow in ipairs(flows) do
if(flow["cli.ip"] == _GET["host"]) then
peer = hostinfo2hostkey(flow, "srv")
@ -47,10 +48,6 @@ for _, flow in pairs(flows) do
tot = tot + v
end
-- Print up to this number of entries
local max_num_peers = 10
local num = 0
local res = {}
for peer,value in pairsByValues(peers, rev) do
@ -71,11 +68,6 @@ for peer,value in pairsByValues(peers, rev) do
end
end
end
num = num + 1
if(num == max_num_peers) then
break
end
end
end
-- tprint(res)