Fixes stats not returned entirely

This commit is contained in:
MatteoBiscosi 2022-04-06 10:37:54 +02:00
parent 2bb7050f95
commit 1b0ca2c507
2 changed files with 49 additions and 38 deletions

View file

@ -23,6 +23,9 @@ local ifid = _GET["ifid"]
local ndpistats_mode = _GET["ndpistats_mode"]
local breed = _GET["breed"]
local ndpi_category = _GET["ndpi_category"]
local get_all_values = (_GET["all_values"] or "false")
local collapse_stats = (_GET["collapse_stats"] or "true")
local max_values = tonumber(_GET["max_values"] or 5)
if isEmptyString(ifid) then
rc = rest_utils.consts.err.invalid_interface
@ -70,43 +73,48 @@ if stats == nil then
end
if(ndpistats_mode == "count") then
tot = 0
tot = 0
for k, v in pairs(stats) do
tot = tot + v
stats[k] = tonumber(v)
end
for k, v in pairs(stats) do
tot = tot + v
stats[k] = tonumber(v)
end
local threshold = (tot * 3) / 100
local num = 0
for k, v in pairsByValues(stats, rev) do
if((num < 5) and (v > threshold)) then
res[#res + 1] = {
label = k,
value = v,
url = getAppUrl(k),
}
num = num + 1
tot = tot - v
else
break
end
end
local threshold = (tot * 3) / 100
local num = 0
if(tot > 0) then
if(get_all_values == "true") then
max_values = 65535 -- ndpi protocols are u_int16_t, so the max numeric value is 65535
end
for k, v in pairsByValues(stats, rev) do
if((num < max_values) and (v > threshold)) then
res[#res + 1] = {
label = i18n("other"),
value = tot,
label = k,
value = v,
url = getAppUrl(k),
}
elseif(num == 0) then
res[#res + 1] = {
label = i18n("no_flows"),
value = 0,
}
end
num = num + 1
tot = tot - v
else
break
end
end
rest_utils.answer(rc, res)
return
if(tot > 0) then
res[#res + 1] = {
label = i18n("other"),
value = tot,
}
elseif(num == 0) then
res[#res + 1] = {
label = i18n("no_flows"),
value = 0,
}
end
rest_utils.answer(rc, res)
return
end
local _ifstats = computeL7Stats(stats, show_breed, show_ndpi_category)
@ -120,5 +128,8 @@ for key, value in pairsByValues(_ifstats, rev) do
}
end
local collapsed = stats_utils.collapse_stats(res, 1, 3 --[[ threshold ]])
rest_utils.answer(rc, collapsed)
if collapse_stats == "true" then
res = stats_utils.collapse_stats(res, 1, 3 --[[ threshold ]])
end
rest_utils.answer(rc, res)