ntopng/scripts/lua/if_stats_ndpi.lua
Emanuele Faranda 4cbe45a948
New pro charts features and timeseries api (#1865)
* Integrate modified nvd3 library with zoom and multicharts working support

* Fix count in RRD driver

* Initial chart ajax migration

* Update nvd3 with zoom stack support

* Fix RRD listSeries with directories

* Work in progress graphs

* Compatibility fix

* Initial support for schema based api

* Add missing script

* Fix listSeries for existance check

* Implement topk timseries api

* Implement topk queries and fix labels and formats

* Migrate interface top sender and receivers

* Migrate charts to new API

* Move timeseries list for menu inside respective scripts

* Add support for extended labels

* Fix missing fields while chaning graph resolution

Also Rename drawRRD in drawGraphs

* Fix historical tabs

* Add missing time fence in influx topk

* Add graphs support for custom statistics visualization

* Initial support for graphs statistics footer

* Implement statistics in single graphs for RRD driver

* Move sampling function into the driver and fix graph statistics

* Fix max/min value offset

* Implement influxdb sampling use built-in FILL

* Implement stats and total serie in influxdb driver

* Update nvd3 with multiChart fixes

* Update nvd3 with new multiChart fixes

* RRD driver fixes

* Move metrics type from single metric to schema

* Handle ajax errors and empty data in charts

* Fix flow device interfaces graphs

* Use timeserie label as timeseries dropdown text

* Implement topk aggregation into one data serie

* ts_utils module now provides all the schemas

* Migrate ntop.exist(rrd) to ts_utils.exist

* Fix timeseries dropdown label

* L4 protos fixes for charts

* Migrate getProtoVolume to new API

* Integrate nvd3 fix for tooltip position

* Initial community graphs migration to timseries API

* Fix community timeseries dropdown and historical tabs

* Hide total serie by default

* Remove l4 protos from topk charts
2018-07-18 15:09:19 +02:00

110 lines
2.9 KiB
Lua

--
-- (C) 2013-18 - ntop.org
--
dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
require "graph_utils"
local ts_utils = require("ts_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
-- Add ARP to stats
if(ifstats.stats ~= nil) then
local arp = { }
arp["bytes.sent"] = 0
arp["bytes.rcvd"] = ifstats.eth["ARP_bytes"]
arp["packets.sent"] = 0
arp["packets.rcvd"] = ifstats.eth["ARP_packets"]
arp.breed = "Unrated"
ifstats["ndpi"]["ARP"] = arp
if(ifstats["ndpi"]["Unknown"] ~= nil) then
ifstats["ndpi"]["Unknown"]["bytes.rcvd"] = ifstats["ndpi"]["Unknown"]["bytes.rcvd"] - ifstats.eth["ARP_bytes"]
ifstats["ndpi"]["Unknown"]["packets.rcvd"] = ifstats["ndpi"]["Unknown"]["packets.rcvd"] - ifstats.eth["ARP_packets"]
end
end
local total = ifstats.stats.bytes
local vals = {}
for k, v in pairs(ifstats["ndpi"]) do
-- io.write("->"..k.."\n")
if v["bytes.rcvd"] > 0 or v["bytes.sent"] > 0 then
vals[k] = k
end
end
table.sort(vals)
if(json_format) then print('[\n') end
local num = 0
for _k in pairsByKeys(vals, asc) do
k = vals[_k]
if(not(json_format)) then
print('<tr id="t_protocol_'..k..'">')
print('<th style="width: 33%;">')
else
if(num > 0) then
print(',\n')
end
end
if(ts_utils.exists("iface:ndpi", {ifid=ifid, protocol=k})) then
if(not(json_format)) then
print("<A HREF=\""..ntop.getHttpPrefix().."/lua/if_stats.lua?ifid=" .. ifid .. "&page=historical&ts_schema=iface:ndpi&protocol=".. k .."\">".. k .." "..formatBreed(ifstats["ndpi"][k]["breed"]).."</A>")
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
if(k ~= "ARP") then print(" <A HREF=\""..ntop.getHttpPrefix().."/lua/flows_stats.lua?application="..k.."\"><i class=\"fa fa-search-plus\"></i></A>") end
print("</th><td class=\"text-right\" style=\"width: 20%;\">" ..bytesToSize(t).. "</td>")
print("<td ><span style=\"width: 60%; float: left;\">")
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