mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-06 03:45:26 +00:00
Uses stats rather than grouped hosts data for network stats
This commit is contained in:
parent
244d45eb00
commit
74c545d079
14 changed files with 247 additions and 31 deletions
|
|
@ -17,7 +17,6 @@ local currentPage = _GET["currentPage"]
|
|||
local perPage = _GET["perPage"]
|
||||
local sortColumn = _GET["sortColumn"]
|
||||
local sortOrder = _GET["sortOrder"]
|
||||
|
||||
local group_col = _GET["grouped_by"]
|
||||
local network_n = _GET["network"]
|
||||
local country_n = _GET["country"]
|
||||
|
|
|
|||
25
scripts/lua/get_network_data.lua
Normal file
25
scripts/lua/get_network_data.lua
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
--
|
||||
-- (C) 2013-19 - ntop.org
|
||||
--
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
require "lua_utils"
|
||||
require "network_utils"
|
||||
local json = require("dkjson")
|
||||
|
||||
sendHTTPContentTypeHeader('text/html')
|
||||
|
||||
-- sendHTTPHeader('application/json')
|
||||
|
||||
local network = tonumber(_GET["network"])
|
||||
|
||||
local n = interface.getNetworkStats(network)
|
||||
local res = {}
|
||||
|
||||
for k, v in pairs(n) do
|
||||
res = network2record(interface.getStats()["id"], v)
|
||||
break
|
||||
end
|
||||
|
||||
print(json.encode(res, nil))
|
||||
101
scripts/lua/get_networks_data.lua
Normal file
101
scripts/lua/get_networks_data.lua
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
--
|
||||
-- (C) 2013-19 - ntop.org
|
||||
--
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
require "lua_utils"
|
||||
require "network_utils"
|
||||
|
||||
local json = require("dkjson")
|
||||
sendHTTPContentTypeHeader('text/html')
|
||||
|
||||
-- Table parameters
|
||||
local currentPage = _GET["currentPage"]
|
||||
local perPage = _GET["perPage"]
|
||||
local sortColumn = _GET["sortColumn"]
|
||||
local sortOrder = _GET["sortOrder"]
|
||||
|
||||
local sortPrefs = "network"
|
||||
|
||||
if((sortColumn == nil) or (sortColumn == "column_"))then
|
||||
sortColumn = getDefaultTableSort(sortPrefs)
|
||||
else
|
||||
if((sortColumn ~= "column_")
|
||||
and (sortColumn ~= "")) then
|
||||
tablePreferences("sort_"..sortPrefs,sortColumn)
|
||||
end
|
||||
end
|
||||
|
||||
if(sortOrder == nil) then
|
||||
sortOrder = getDefaultTableSortOrder(sortPrefs)
|
||||
else
|
||||
if((sortColumn ~= "column_")
|
||||
and (sortColumn ~= "")) then
|
||||
tablePreferences("sort_order_"..sortPrefs,sortOrder)
|
||||
end
|
||||
end
|
||||
|
||||
if(currentPage == nil) then
|
||||
currentPage = 1
|
||||
else
|
||||
currentPage = tonumber(currentPage)
|
||||
end
|
||||
|
||||
if(perPage == nil) then
|
||||
perPage = getDefaultTableSize()
|
||||
else
|
||||
perPage = tonumber(perPage)
|
||||
tablePreferences("rows_number", perPage)
|
||||
end
|
||||
|
||||
local to_skip = (currentPage-1) * perPage
|
||||
|
||||
if(sortOrder == "desc") then sOrder = false else sOrder = true end
|
||||
|
||||
local networks_stats = interface.getNetworksStats()
|
||||
local total_rows = 0
|
||||
|
||||
local sort_helper = {}
|
||||
for n, ns in pairs(networks_stats) do
|
||||
total_rows = total_rows + 1
|
||||
|
||||
if sortColumn == "column_hosts" then
|
||||
sort_helper[n] = ns["num_hosts"]
|
||||
elseif sortColumn == "column_thpt" then
|
||||
sort_helper[n] = ns["throughput_bps"]
|
||||
elseif sortColumn == "column_traffic" then
|
||||
sort_helper[n] = ns["bytes.sent"] + ns["bytes.rcvd"]
|
||||
else
|
||||
sort_helper[n] = getLocalNetworkAlias(ns["network_key"])
|
||||
end
|
||||
end
|
||||
|
||||
local res_formatted = {}
|
||||
local cur_row = 0
|
||||
|
||||
for n, _ in pairsByValues(sort_helper, ternary(sOrder, asc, rev)) do
|
||||
cur_row = cur_row + 1
|
||||
|
||||
if cur_row <= to_skip then
|
||||
goto continue
|
||||
end
|
||||
|
||||
local record = network2record(interface.getStats()["id"], networks_stats[n])
|
||||
res_formatted[#res_formatted + 1] = record
|
||||
|
||||
if cur_row >= perPage then
|
||||
break
|
||||
end
|
||||
|
||||
::continue::
|
||||
end
|
||||
|
||||
local result = {}
|
||||
result["perPage"] = perPage
|
||||
result["currentPage"] = currentPage
|
||||
result["totalRows"] = total_rows
|
||||
result["data"] = res_formatted
|
||||
result["sort"] = {{sortColumn, sortOrder}}
|
||||
|
||||
print(json.encode(result, nil))
|
||||
37
scripts/lua/modules/network_utils.lua
Normal file
37
scripts/lua/modules/network_utils.lua
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
require "lua_utils"
|
||||
require "graph_utils"
|
||||
local ts_utils = require "ts_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 progress-bar-warning' style='width: "
|
||||
.. sent2rcvd .."%;'>Sent</div><div class='progress-bar progress-bar-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"])
|
||||
|
||||
record["column_chart"] = ""
|
||||
|
||||
record["column_chart"] = '<A HREF="'..ntop.getHttpPrefix()..'/lua/network_details.lua?network='..network["network_id"]..'&page=historical"><i class=\'fa fa-area-chart fa-lg\'></i></A>'
|
||||
|
||||
return record
|
||||
end
|
||||
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
--
|
||||
-- (C) 2013-18 - ntop.org
|
||||
-- (C) 2013-19 - ntop.org
|
||||
--
|
||||
|
||||
dirs = ntop.getDirs()
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
|
|
@ -39,7 +39,7 @@ print [[
|
|||
<div id="table-network"></div>
|
||||
<script>
|
||||
var url_update = "]]
|
||||
print(getPageUrl(ntop.getHttpPrefix().."/lua/get_grouped_hosts_data.lua", page_params))
|
||||
print(getPageUrl(ntop.getHttpPrefix().."/lua/get_networks_data.lua", page_params))
|
||||
print ('";')
|
||||
ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/network_stats_id.inc")
|
||||
|
||||
|
|
@ -103,23 +103,6 @@ print [[
|
|||
textAlign: 'center'
|
||||
}
|
||||
|
||||
},
|
||||
{
|
||||
title: "]] print(i18n("show_alerts.alerts")) print[[",
|
||||
field: "column_alerts",
|
||||
sortable: true,
|
||||
css: {
|
||||
textAlign: 'center'
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "]] print(i18n("seen_since")) print[[",
|
||||
field: "column_since",
|
||||
sortable: true,
|
||||
css: {
|
||||
textAlign: 'center'
|
||||
}
|
||||
|
||||
},
|
||||
]]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue