1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
--
-- (C) 2013-22 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
local graph_utils = require "graph_utils"
local categories_utils = require "categories_utils"
local ifid = _GET["ifid"]
if ifid ~= nil and ifid ~= "" then
if_name = getInterfaceName(ifid)
else
if_name = ifname
ifid = interface.name2id(ifname)
end
interface.select(if_name)
local ifstats = interface.getStats()
local format = _GET["format"]
if(format == "json") then
sendHTTPHeader('application/json')
json_format = true
else
sendHTTPContentTypeHeader('text/html')
json_format = false
end
local total = ifstats.stats.bytes
if(json_format) then print('[\n') end
local num = 0
for k, v in pairsByKeys(ifstats["ndpi_categories"], asc) do
local label = getCategoryLabel(k)
if(not(json_format)) then
print('<tr id="t_protocol_'..k..'">')
print('<th style="width: 20%;">')
else
if(num > 0) then
print(',\n')
end
end
if(areInterfaceCategoriesTimeseriesEnabled(ifid)) then
if(not(json_format)) then
print("<A HREF=\""..ntop.getHttpPrefix().."/lua/if_stats.lua?ifid=" .. ifid .. "&page=historical&ts_schema=iface:ndpi_categories&category=".. k .."\">".. label .." </A>")
else
print('{ "proto": "'..k..'", ')
end
else
if(not(json_format)) then
print(k)
else
print('{ "proto": "'..k..'", ')
end
end
local t = v["bytes"]
if(not(json_format)) then
print("</th>")
print('<td style="width: 50%;">')
print(categories_utils.get_category_protocols_list(v.category))
print("</td>")
print("<td class=\"text-end\" style=\"width: 10%;\">" ..bytesToSize(t).. "</td>")
print("<td ><span style=\"width: 60%; float: left;\">")
graph_utils.percentageBar(total, t, "") -- k
-- print("</td>\n")
print("</span><span style=\"width: 40%; margin-left: 15px;\" >" ..round((t * 100)/total, 1).. " %</span></td></tr>\n")
else
print('"bytes": '..tostring(t)..' }')
end
num = num + 1
end
if(json_format) then print('\n]\n') end
|