Fixed stats on System / Redis Page (#8943)

This commit is contained in:
Manuel Ceroni 2025-02-05 16:23:59 +01:00 committed by GitHub
parent d6ab54ec66
commit 5c605200d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 139 additions and 142 deletions

View file

@ -11,50 +11,8 @@ local rest_utils = require("rest_utils")
-- ################################################
local currentPage = _GET["currentPage"]
local perPage = _GET["perPage"]
local sortColumn = _GET["sortColumn"]
local sortOrder = _GET["sortOrder"]
local cmd_ids_filter = _GET["custom_hosts"]
local sortPrefs = "redis_commands_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
-- ################################################
if(cmd_ids_filter) then
@ -62,62 +20,21 @@ if(cmd_ids_filter) then
end
local commands_stats = ntop.getCacheStats() or {}
local totalRows = 0
local sort_to_key = {}
for command, hits in pairs(commands_stats) do
if(cmd_ids_filter and (cmd_ids_filter[command] == nil)) then
goto continue
end
if(sortColumn == "column_command") then
sort_to_key[command] = command
else
sort_to_key[command] = hits
end
totalRows = totalRows + 1
::continue::
end
-- ################################################
local res = {}
local i = 0
local charts_available = script_manager.systemTimeseriesEnabled()
for key in pairsByValues(sort_to_key, sOrder) do
if i >= to_skip + perPage then
break
for command, hits in pairs(commands_stats) do
if(charts_available) then
chart = '<a href="?page=historical&redis_command='..command..'&ts_schema=redis:hits"><i class=\'fas fa-chart-area fa-lg\'></i></a>'
end
if (i >= to_skip) then
local chart = ""
local value = commands_stats[key]
if(charts_available) then
chart = '<a href="?page=historical&redis_command='..key..'&ts_schema=redis:hits"><i class=\'fas fa-chart-area fa-lg\'></i></a>'
end
res[#res + 1] = {
column_key = key,
column_command = string.upper(string.sub(key, 5)),
column_chart = chart,
column_hits = value,
}
end
i = i + 1
res[#res + 1] = {
column_command = string.upper(string.sub(command, 5)),
column_chart = chart,
column_hits = hits,
}
end
-- ################################################
local result = {}
result["perPage"] = perPage
result["currentPage"] = currentPage
result["totalRows"] = totalRows
result["data"] = res
result["sort"] = {{sortColumn, sortOrder}}
rest_utils.answer(rest_utils.consts.success.ok, result)
rest_utils.extended_answer(rest_utils.consts.success.ok, res, {
["recordsTotal"] = #res
})