-- -- (C) 2013-15 - ntop.org -- dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path require "lua_utils" require "graph_utils" interface.select(ifname) ifstats = aggregateInterfaceStats(aggregateInterfaceStats(interface.getStats())) format = _GET["format"] if(format == "json") then sendHTTPHeader('application/json') json_format = true else sendHTTPHeader('text/html; charset=iso-8859-1') json_format = false end total = ifstats["bytes"] vals = {} for k in pairs(ifstats["ndpi"]) do vals[k] = k end table.sort(vals) if(json_format) then print('[\n') end num = 0 for _k in pairsByKeys(vals, rev) do k = vals[_k] if(not(json_format)) then print('') print('') else if(num > 0) then print(',\n') end end fname = getRRDName(ifstats.id, nil, k..".rrd") if(ntop.exists(fname)) then if(not(json_format)) then print("".. k .." "..formatBreed(ifstats["ndpi"][k]["breed"]).."") else print('{ "proto": "'..k..'", "breed": "'..ifstats["ndpi"][k]["breed"]..'", ') end else if(not(json_format)) then print(k.." "..formatBreed(ifstats["ndpi"][k]["breed"])) else print('{ "proto": "'..k..'", ') end end t = ifstats["ndpi"][k]["bytes.sent"]+ifstats["ndpi"][k]["bytes.rcvd"] if(not(json_format)) then print(" ") print("" .. bytesToSize(t).. "") print("") percentageBar(total, t, "") -- k -- print("\n") print("" ..round((t * 100)/total, 2).. " %\n") else print('"bytes": '..t..' }') end num = num + 1 end if(json_format) then print('\n]\n') end