Implements data cleanup for inactive interfaces

Implements #1971
This commit is contained in:
Simone Mainardi 2018-09-07 15:55:14 +02:00
parent 7c49514ba0
commit bd27304c54
6 changed files with 266 additions and 23 deletions

View file

@ -777,17 +777,19 @@ end
-- ########################################################
function db_utils.harverstExpiredMySQLFlows(ifname, mysql_retention, verbose)
interface.select(ifname)
local dbtables = {"flowsv4", "flowsv6"}
if useAggregatedFlows() then
dbtables[#dbtables+1] = "aggrflowsv4"
dbtables[#dbtables+1] = "aggrflowsv6"
end
if tonumber(ifname) == nil then
ifname = getInterfaceId(ifname)
end
for _, tb in pairs(dbtables) do
local sql = "DELETE FROM "..tb.." where FIRST_SWITCHED < "..mysql_retention
sql = sql.." AND (INTERFACE_ID = "..getInterfaceId(ifname)..")"
sql = sql.." AND (INTERFACE_ID = "..ifname..")"
sql = sql.." AND (NTOPNG_INSTANCE_NAME='"..ntop.getPrefs()["instance_name"].."' OR NTOPNG_INSTANCE_NAME IS NULL OR NTOPNG_INSTANCE_NAME='')"
interface.execSQLQuery(sql)
if(verbose) then io.write(sql.."\n") end