ntopng/scripts/lua/get_ts.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

67 lines
1.5 KiB
Lua

--
-- (C) 2013-18 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
if ntop.isPro() then
package.path = dirs.installdir .. "/pro/scripts/lua/modules/?.lua;" .. package.path
end
require "lua_utils"
local ts_utils = require("ts_utils")
local json = require("dkjson")
local schema_id = _GET["ts_schema"]
local query = _GET["ts_query"]
local tstart = tonumber(_GET["epoch_begin"]) or (os.time() - 3600)
local tend = tonumber(_GET["epoch_end"]) or os.time()
-- convert the query into fields
local tags = tsQueryToTags(_GET["ts_query"])
if tags.ifid then
interface.select(tags.ifid)
end
sendHTTPHeader('application/json')
local res
if starts(schema_id, "top:") then
local schema_id = split(schema_id, "top:")[2]
res = ts_utils.queryTopk(schema_id, tags, tstart, tend)
else
res = ts_utils.query(schema_id, tags, tstart, tend)
end
if res == nil then
print("[]")
return
end
-- TODO make a script parameter?
local extend_labels = true
if extend_labels then
local tags = res.series and res.series[1] and res.series[1].tags
if tags then
if tags.if_index and tags.device then
-- SNMP port name
local snmp_device = require "snmp_device"
snmp_device.init(tags.device)
for _, serie in pairs(res.series) do
local interfaces = snmp_device.get_device()["interfaces"]
local label = shortenString(get_snmp_interface_label(interfaces[serie.tags.if_index]))
serie.ext_label = label
end
end
end
end
print(json.encode(res))