ntopng/scripts/lua/get_treemap.lua
Luca 11f8c934d0 Reworked hosts listing in order to avoid/limit out-of-memory issues
Implemented aggregation of hosts and flows when using views
2015-12-27 18:55:50 +01:00

80 lines
No EOL
1.2 KiB
Lua

--
-- (C) 2013-15 - ntop.org
--
dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
sendHTTPHeader('application/json')
interface.select(ifname)
hosts_stats,total = aggregateHostsStats(interface.getHostsInfo())
print [[
{
"name": "flare",
"children": [
{
"name": "analytics",
"children": [
{
"name": "Local Hosts",
"children": [
]]
tot = 0
for key, value in pairs(hosts_stats) do
tot = tot + hosts_stats[key]["bytes.sent"]+hosts_stats[key]["bytes.rcvd"]
end
threshold = tot/40
other = 0
num = 0
for key, value in pairs(hosts_stats) do
val = hosts_stats[key]["bytes.sent"]+hosts_stats[key]["bytes.rcvd"]
if(val > threshold) then
if(num > 0) then print(",\n") else print("\n") end
res = ntop.getResolvedAddress(key)
--if(res == nil) then res = "AAA" end
print("{ \"name\": \"" .. res .. "\", \"size\": " .. (hosts_stats[key]["bytes.sent"]+hosts_stats[key]["bytes.rcvd"]).. "} ")
num = num + 1
else
other = other + val
end
end
print [[
]
}
]]
if(other > 0) then
print [[,
{
"name": "Remote Hosts",
"children": [
]]
print("{ \"name\": \"Other Hosts\", \"size\": " .. other .. "} ")
print [[
]
}
]]
end
print [[
]
}
]
}
]]