Add trace when alerts queue limit is exceeded

This commit is contained in:
emanuele-f 2019-07-15 15:37:20 +02:00
parent 15879e635d
commit 9fa3b7920c
3 changed files with 17 additions and 6 deletions

View file

@ -115,9 +115,14 @@ local function formatThresholdCross(ifid, alert, threshold_info)
local entity = formatAlertEntity(ifid, alertEntityRaw(alert["alert_entity"]), alert["alert_entity_val"])
local engine_label = alertEngineLabel(alertEngine(sec2granularity(alert["alert_granularity"])))
-- TODO i18n
return engine_label.." <b>".. threshold_info.metric .."</b> crossed by ".. entity ..
" ["..threshold_info.value.." &"..(threshold_info.operator).."; "..threshold_info.threshold.."]"
return i18n("alert_messages.threshold_crossed", {
granularity = engine_label,
metric = threshold_info.metric,
entity = entity,
value = threshold_info.value,
op = "&"..threshold_info.operator..";",
threshold = threshold_info.threshold,
})
end
-- ##############################################

View file

@ -13,7 +13,7 @@ local do_trace = false
local alerts = {}
local MAX_NUM_ENQUEUED_ALERTS_EVENTS = 100
local MAX_NUM_ENQUEUED_ALERTS_EVENTS = 4096
local ALERTS_EVENTS_QUEUE = "ntopng.cache.alerts_events_queue"
local ALERT_CHECKS_MODULES_BASEDIR = dirs.installdir .. "/scripts/callbacks/interface/alerts"
@ -228,9 +228,14 @@ end
local function enqueueAlertEvent(alert_event)
local event_json = json.encode(alert_event)
local trim = nil
ntop.rpushCache(ALERTS_EVENTS_QUEUE, event_json, MAX_NUM_ENQUEUED_ALERTS_EVENTS)
if(ntop.llenCache(ALERTS_EVENTS_QUEUE) > MAX_NUM_ENQUEUED_ALERTS_EVENTS) then
trim = math.ceil(MAX_NUM_ENQUEUED_ALERTS_EVENTS/2)
traceError(TRACE_WARNING, TRACE_CONSOLE, string.format("Alerts event queue too long: dropping %u alerts", trim))
end
ntop.rpushCache(ALERTS_EVENTS_QUEUE, event_json, trim)
return(true)
end