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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
--
-- (C) 2019-22 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
local format_utils = require("format_utils")
local json = require("dkjson")
local ts_utils = require "ts_utils"
local checks = require "checks"
sendHTTPContentTypeHeader('application/json')
-- ################################################
local iffilter = _GET["iffilter"]
local check_target = _GET["check_target"]
local currentPage = _GET["currentPage"]
local perPage = _GET["perPage"]
local sortColumn = _GET["sortColumn"]
local sortOrder = _GET["sortOrder"]
local sortPrefs = "internals_checks_data"
-- ################################################
if isEmptyString(sortColumn) or sortColumn == "column_" then
sortColumn = getDefaultTableSort(sortPrefs)
else
if((sortColumn ~= "column_")
and (sortColumn ~= "")) then
tablePreferences("sort_"..sortPrefs, sortColumn)
end
end
if isEmptyString(_GET["sortColumn"]) then
sortOrder = getDefaultTableSortOrder(sortPrefs, true)
end
if((_GET["sortColumn"] ~= "column_")
and (_GET["sortColumn"] ~= "")) then
tablePreferences("sort_order_"..sortPrefs, sortOrder, true)
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 sOrder = ternary(sortOrder == "asc", asc_insensitive, rev_insensitive)
local to_skip = (currentPage-1) * perPage
-- ################################################
local ifaces_checks_stats = {}
local subdirs_list = checks.listSubdirs()
for _, iface in pairs(interface.getIfNames()) do
if iffilter and iffilter ~= tostring(getInterfaceId(iface)) then
goto continue
end
for _, subdir in ipairs(subdirs_list) do
local subdir_benchmarks = checks.getLastBenchmark(getInterfaceId(iface), subdir["id"])
for mod_k, mod_benchmarks in pairs(subdir_benchmarks) do
for hook_k, hook_benchmark in pairs(mod_benchmarks) do
local flat_k = string.format("%s_%s_%s_%s", getInterfaceId(iface), subdir["id"], mod_k, hook_k)
ifaces_checks_stats[flat_k] = {
iface = iface, ifid = getInterfaceId(iface),
subdir = subdir["label"],
mod_k = mod_k,
hook_k = hook_k,
hook_benchmark = hook_benchmark}
end
end
end
::continue::
end
local totalRows = 0
local sort_to_key = {}
for k, check_stats in pairs(ifaces_checks_stats) do
if check_target then
if check_stats.subdir ~= check_target then
goto continue
end
end
if(sortColumn == "column_last_duration") then
sort_to_key[k] = check_stats.hook_benchmark.tot_elapsed
elseif(sortColumn == "column_last_num_calls") then
sort_to_key[k] = check_stats.hook_benchmark.tot_num_calls
elseif(sortColumn == "column_check_name") then
sort_to_key[k] = check_stats.mod_k
elseif(sortColumn == "column_check_target") then
sort_to_key[k] = check_stats.subdir
elseif(sortColumn == "column_hook") then
sort_to_key[k] = check_stats.hook_k
elseif(sortColumn == "column_name") then
sort_to_key[k] = getHumanReadableInterfaceName(getInterfaceName(check_stats.ifid))
else
sort_to_key[k] = check_stats.subdir
end
totalRows = totalRows + 1
::continue::
end
-- ################################################
local res = {}
local i = 0
for key in pairsByValues(sort_to_key, sOrder) do
if i >= to_skip + perPage then
break
end
if i >= to_skip then
local record = {}
local script_stats = ifaces_checks_stats[key]
local last_duration = script_stats.hook_benchmark.tot_elapsed
local last_num_calls = script_stats.hook_benchmark.tot_num_calls
record["column_key"] = key
record["column_ifid"] = string.format("%i", script_stats.ifid)
record["column_last_duration"] = last_duration * 1000 -- expressed as milliseconds
record["column_last_num_calls"] = last_num_calls
record["column_name"] = string.format('<a href="'..ntop.getHttpPrefix()..'/lua/if_stats.lua?ifid=%i&page=internals&tab=checks">%s</a>', script_stats.ifid, getHumanReadableInterfaceName(getInterfaceName(script_stats.ifid)))
record["column_check_target"] = script_stats.subdir
record["column_check_name"] = script_stats.mod_k
record["column_hook"] = script_stats.hook_k
res[#res + 1] = record
end
i = i + 1
end
-- ################################################
local result = {}
result["perPage"] = perPage
result["currentPage"] = currentPage
result["totalRows"] = totalRows
result["data"] = res
result["sort"] = {{sortColumn, sortOrder}}
print(json.encode(result))
|