ntopng/scripts/lua/modules/network_utils.lua
Simone Mainardi 3744ace4f8 Refactors graph_utils and nv_graph_utils
Addresses #3720

Refactor: create module graph_utils

Refactor: get_timeseries_layout

Refactor: get_default_timeseries

Refactor: getDeviceCommonTimeseries

Refactor: printCategoryDropdownButton

Refactor: printPoolChangeDropdown

Refactor: poolDropdown

Refactor: printProtocolQuota

Refactor: printGraphTopFlows

Refactor: drawGraphs

Refactor: printNotes

Refactor: getMinZoomResolution

Refactor: printSeries

Refactor: zoom_vals

Refactor: getZoomDuration

Refactor: getZoomAtPos

Refactor: stackedProgressBars

Refactor: percentageBar

Refactor: breakdownBar

Refactor: getProtoVolume

Refactor: normalizeSeriesPoints

Refactor: nv_graph_utils

Refactor: extendLabels

Refactor: getAlertGraphLink

Refactor: performCustomQuery

Refactor: drawProGraph

Refactor: unifies nv_graph_utils and graph_utils
2020-04-10 09:47:32 +02:00

38 lines
1.5 KiB
Lua

require "lua_utils"
local graph_utils = require "graph_utils"
-- Get from redis the throughput type bps or pps
local throughput_type = getThroughputType()
local now = os.time()
function network2record(ifId, network)
local record = {}
record["key"] = tostring(network["network_id"])
local network_link = "<A HREF='"..ntop.getHttpPrefix()..'/lua/hosts_stats.lua?network='..network["network_id"].."' title='"..network["network_key"].."'>"..getFullLocalNetworkName(network["network_key"])..'</A>'
record["column_id"] = network_link
record["column_hosts"] = (network["num_hosts"] or 0)..""
local sent2rcvd = round((network["bytes.sent"] * 100) / (network["bytes.sent"] + network["bytes.rcvd"]), 0)
record["column_breakdown"] = "<div class='progress'><div class='progress-bar bg-warning' style='width: "
.. sent2rcvd .."%;'>Sent</div><div class='progress-bar bg-info' style='width: " .. (100-sent2rcvd) .. "%;'>Rcvd</div></div>"
if(throughput_type == "pps") then
record["column_thpt"] = pktsToSize(network["throughput_pps"])
else
record["column_thpt"] = bitsToSize(8*network["throughput_bps"])
end
record["column_traffic"] = bytesToSize(network["bytes.sent"] + network["bytes.rcvd"])
if not areInterfaceTimeseriesEnabled(ifId) then
record["column_chart"] = ""
else
record["column_chart"] = '<A HREF="'..ntop.getHttpPrefix()..'/lua/network_details.lua?network='..network["network_id"]..'&page=historical"><i class=\'fas fa-chart-area fa-lg\'></i></A>'
end
return record
end