Updated data.lua periodic rest

This commit is contained in:
MatteoBiscosi 2022-03-07 19:12:36 +01:00
parent 27c5f784dc
commit 8061a918b3
4 changed files with 149 additions and 81 deletions

View file

@ -63,6 +63,11 @@ local function countHosts()
end
function dumpInterfaceStats(ifid)
-- main interface stats used by periodic data.lua call
if(_GET["type"] == "summary") then
return dumpBriefInterfaceStats(ifid)
end
local interface_name = getInterfaceName(ifid)
interface.select(ifid..'')
@ -269,6 +274,112 @@ function dumpInterfaceStats(ifid)
return res
end
function dumpBriefInterfaceStats(ifid)
local interface_name = getInterfaceName(ifid)
interface.select(ifid..'')
local ifstats = interface.getStats()
local res = {}
if(ifstats ~= nil) then
local uptime = ntop.getUptime()
local prefs = ntop.getPrefs()
-- Round up
local hosts_pctg = math.floor(1+((ifstats.stats.hosts*100)/prefs.max_num_hosts))
local flows_pctg = math.floor(1+((ifstats.stats.flows*100)/prefs.max_num_flows))
local macs_pctg = math.floor(1+((ifstats.stats.current_macs*100)/prefs.max_num_hosts))
res["ifid"] = ifid
res["ifname"] = interface_name
res["drops"] = ifstats.stats_since_reset.drops
res["throughput_bps"] = ifstats.stats.throughput_bps;
if prefs.is_dump_flows_enabled == true then
res["flow_export_drops"] = ifstats.stats_since_reset.flow_export_drops
res["flow_export_count"] = ifstats.stats_since_reset.flow_export_count
end
if auth.has_capability(auth.capabilities.alerts) then
res["engaged_alerts"] = ifstats["num_alerts_engaged"] or 0
res["engaged_alerts_warning"] = ifstats["num_alerts_engaged_by_severity"]["warning"]
res["engaged_alerts_error"] = ifstats["num_alerts_engaged_by_severity"]["error"]
res["alerted_flows"] = ifstats["num_alerted_flows"] or 0
res["alerted_flows_warning"] = ifstats["num_alerted_flows_warning"] or 0
res["alerted_flows_error"] = ifstats["num_alerted_flows_error"] or 0
end
if periodic_activities_utils.have_degraded_performance() then
res["degraded_performance"] = true
end
if not userHasRestrictions() then
res["num_flows"] = ifstats.stats.flows
res["num_hosts"] = ifstats.stats.hosts
res["num_local_hosts"] = ifstats.stats.local_hosts
res["num_devices"] = ifstats.stats.devices
else
res["num_hosts"] = countHosts().hosts
res["num_local_hosts"] = countHosts().local_hosts
end
res["localtime"] = os.date("%H:%M:%S %z", res["epoch"])
res["uptime"] = secondsToTime(uptime)
if ntop.isPro() then
local product_info = ntop.getInfo(true)
if product_info["pro.out_of_maintenance"] then
res["out_of_maintenance"] = true
end
end
res["hosts_pctg"] = hosts_pctg
res["flows_pctg"] = flows_pctg
res["macs_pctg"] = macs_pctg
if isAdministrator() then
res["num_live_captures"] = ifstats.stats.num_live_captures
end
local ingress_thpt = ifstats["eth"]["ingress"]["throughput"]
local egress_thpt = ifstats["eth"]["egress"]["throughput"]
res["throughput"] = {
download = ingress_thpt["bps"],
upload = egress_thpt["bps"]
}
if recording_utils.isAvailable() then
if recording_utils.isEnabled(ifstats.id) then
if recording_utils.isActive(ifstats.id) then
res["traffic_recording"] = "recording"
else
res["traffic_recording"] = "failed"
end
end
if recording_utils.isEnabled(ifstats.id) then
local jobs_info = recording_utils.extractionJobsInfo(ifstats.id)
if jobs_info.ready > 0 then
res["traffic_extraction"] = "ready"
elseif jobs_info.total > 0 then
res["traffic_extraction"] = jobs_info.total
end
res["traffic_extraction_num_tasks"] = jobs_info.total
end
end
-- Adding a preference if active discovery is enabled
res["active_discovery_active"] = ntop.getPref("ntopng.prefs.is_periodic_network_discovery_running.ifid_" .. interface.getId()) == "1"
end
return res
end
-- ###############################
if(iffilter == "all") then