improved page layouts and added stats_utils for pie charts (#4653)

This commit is contained in:
gabryon99 2020-11-26 16:56:40 +01:00
parent 4fa3089628
commit 9d8fded73c
15 changed files with 66 additions and 103 deletions

View file

@ -7,6 +7,7 @@ package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
local rest_utils = require("rest_utils")
local stats_utils = require("stats_utils")
--
-- Read statistics about nDPI application protocols for a hsot
@ -63,19 +64,7 @@ tot = stats["bytes.sent"] + stats["bytes.rcvd"]
local _ifstats = computeL7Stats(stats, show_breed, show_ndpi_category)
-- Print up to this number of entries
local max_num_entries = 5
-- Print entries whose value >= 3% of the total
local threshold = (tot * 3) / 100
local num = 0
local accumulate = 0
for key, value in pairsByValues(_ifstats, rev) do
if(value < threshold) then
break
end
local duration = 0
@ -89,24 +78,8 @@ for key, value in pairsByValues(_ifstats, rev) do
duration = duration,
}
accumulate = accumulate + value
num = num + 1
if(num == max_num_entries) then
break
end
end
if(tot == 0) then
tot = 1
end
local collapsed = stats_utils.collapse_stats(res, 5, 3 --[[ threshold ]])
-- In case there is some leftover do print it as "Other"
if(accumulate < tot) then
res[#res + 1] = {
label = i18n("other"),
value = (tot-accumulate),
}
end
rest_utils.answer(rc, res)
rest_utils.answer(rc, collapsed)