Optimized pools lock/unlock removing redis with a lock in ntopng

This commit is contained in:
Luca Deri 2022-09-05 20:00:29 +02:00
parent a9f7c69fab
commit be90bf50df
11 changed files with 150 additions and 32 deletions

View file

@ -21,6 +21,8 @@ if(ntop.isPro()) then
-- NOTE: import snmp_utils below to avoid import cycles
end
alert_consts.SEPARATOR = ';'
-- NOTE: sqlite can handle about 10-50 alerts/sec
alert_consts.MAX_NUM_QUEUED_ALERTS_PER_MODULE = 1024 -- should match ALERTS_MANAGER_MAX_ENTITY_ALERTS

View file

@ -32,8 +32,6 @@ end
local alert_utils = {}
alert_utils.SEPARATOR = ';'
-- ##############################################
local function alertTypeDescription(alert_key, entity_id)
@ -619,7 +617,7 @@ function alert_utils.getLinkToPastFlows(ifid, alert, alert_json)
-- Join the TAG filters using the predefined operator
local final_filter = {}
for _, tag in pairs(tags) do
final_filter[tag.name] = string.format("%s%s%s", tag.val, alert_utils.SEPARATOR, tag.op)
final_filter[tag.name] = string.format("%s%s%s", tag.val, alert_consts.SEPARATOR, tag.op)
end
-- tprint({formatEpoch(epoch_begin), formatEpoch(epoch_end), formatEpoch(tonumber(alert.tstamp)), formatEpoch(tonumber(alert.tstamp_end))})

View file

@ -506,7 +506,7 @@ end
function am_utils.deleteHost(host, measurement)
local ts_utils = require("ts_utils")
local alert_utils = require("alert_utils")
-- local alert_utils = require("alert_utils")
-- NOTE: system interface must be manually sected and then unselected
local old_iface = tostring(interface.getId())

View file

@ -196,27 +196,26 @@ end
-- ##############################################
local _use_lock = true
function pools:_lock()
local max_lock_duration = 5 -- seconds
local max_lock_attempts = 5 -- give up after at most this number of attempts
local lock_key = self:_get_pool_lock_key()
local max_lock_duration = 5 -- seconds
for i = 1, max_lock_attempts do
local value_set = ntop.setnxCache(lock_key, "1", max_lock_duration)
if value_set then
return true -- lock acquired
end
ntop.msleep(1000)
end
return false -- lock not acquired
if(_use_lock) then
-- tprint(debug.traceback()) -- TODO: remove this useless lock
return ntop.poolsLock(max_lock_duration)
else
return true
end
end
-- ##############################################
function pools:_unlock() ntop.delCache(self:_get_pool_lock_key()) end
function pools:_unlock()
if(_use_lock) then
ntop.poolsUnlock()
end
end
-- ##############################################

View file

@ -13,7 +13,6 @@ require "lua_utils"
local alert_entities = require "alert_entities"
local alert_consts = require "alert_consts"
local alert_severities = require "alert_severities"
local alert_utils = require "alert_utils"
local host_pools = require "host_pools"
local dscp_consts = require "dscp_consts"
local country_codes = require "country_codes"
@ -23,7 +22,7 @@ local snmp_filter_options_cache
local tag_utils = {}
-- Operator Separator in query strings
tag_utils.SEPARATOR = alert_utils.SEPARATOR
tag_utils.SEPARATOR = alert_consts.SEPARATOR
-- #####################################

View file

@ -8,8 +8,6 @@ package.path = dirs.installdir .. "/scripts/lua/modules/pools/?.lua;" .. package
require "lua_utils"
local graph_utils = require "graph_utils"
local alert_utils = require "alert_utils"
local host_pools = require "host_pools"
local host_pools_instance = host_pools:create()
local callback_utils = require "callback_utils"
local ts_utils = require "ts_utils_core"
local format_utils = require "format_utils"
@ -921,7 +919,10 @@ function ts_dump.run_5min_dump(_ifname, ifstats, config, when, verbose)
-- Save Host Pools stats every 5 minutes
if((ntop.isPro()) and (tostring(config.host_pools_rrd_creation) == "1")) then
host_pools_instance:updateRRDs(ifstats.id, true --[[ also dump nDPI data ]], verbose)
local host_pools = require "host_pools"
local host_pools_instance = host_pools:create()
host_pools_instance:updateRRDs(ifstats.id, true --[[ also dump nDPI data ]], verbose)
end
end