ntopng/scripts/lua/modules/country_utils.lua
GabrieleDeri 6801ec1034
Added ai stats page, updated breakdown, 3x speedup dist, removed deps on npm (#10236)
* Added ai stats page, updated breakdown style, 3x speedup npm run build, removed deps on npm

* Added ai stats page href

* Fixes ai stats page

* Update dist

* Fixes create_dist
2026-03-31 18:14:06 +02:00

39 lines
1.5 KiB
Lua

require "lua_utils"
local format_utils = require "format_utils"
-- Get from redis the throughput type bps or pps
local throughput_type = getThroughputType()
local now = os.time()
function country2record(ifId, country)
local record = {}
record["key"] = tostring(country["country"])
local country_link = "<A HREF='"..ntop.getHttpPrefix()..'/lua/hosts_stats.lua?country='..country["country"].."' title='"..country["country"].."'>"..country["country"]..'</A>'
record["column_id"] = getFlag(country["country"]).."&nbsp&nbsp" .. country_link
record["column_score"] = format_high_num_value_for_tables(country, "score")
record["column_hosts"] = format_high_num_value_for_tables(country, "num_hosts")
record["column_since"] = secondsToTime(now - country["seen.first"] + 1)
local sent2rcvd = round((country["egress"] * 100) / (country["egress"] + country["ingress"]), 0)
record["column_breakdown"] = format_utils.createBreakdown(sent2rcvd, 100 - sent2rcvd, "Sent", "Rcvd")
if(throughput_type == "pps") then
record["column_thpt"] = pktsToSize(country["throughput_pps"])
else
record["column_thpt"] = bitsToSize(8*country["throughput_bps"])
end
record["column_traffic"] = bytesToSize(country["bytes"])
record["column_chart"] = ""
if areCountryTimeseriesEnabled(ifId) then
record["column_chart"] = '<A HREF="'..ntop.getHttpPrefix()..'/lua/country_details.lua?country='..country["country"]..'&page=historical"><i class=\'fas fa-chart-area fa-lg\'></i></A>'
end
return record
end