--
-- (C) 2013-22 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
if((dirs.scriptdir ~= nil) and (dirs.scriptdir ~= "")) then package.path = dirs.scriptdir .. "/lua/modules/?.lua;" .. package.path end
require "lua_utils"
local page_utils = require("page_utils")
local script_manager = require("script_manager")
local graph_utils = require("graph_utils")
local charts_available = script_manager.systemTimeseriesEnabled()
if not isAllowedSystemInterface() then
return
end
sendHTTPContentTypeHeader('text/html')
page_utils.set_active_menu_entry(page_utils.menu_entries.redis_monitor)
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
local page = _GET["page"] or "overview"
local url = script_manager.getMonitorUrl("redis_monitor.lua") .. "?ifid=" .. getInterfaceId(ifname)
page_utils.print_navbar("Redis", url,
{
{
active = page == "overview" or not page,
page_name = "overview",
label = "",
},
{
active = page == "stats",
page_name = "stats",
label = "",
},
{
hidden = not charts_available,
active = page == "historical",
page_name = "historical",
label = "",
},
}
)
-- #######################################################
if(page == "overview") then
local fa_external = ""
local tags = {ifid=getSystemInterfaceId()}
print("
\n")
if not ntop.isWindows() then
-- NOTE: on Windows, some stats are missing from script.getRedisStatus()
print("".. i18n("system_stats.health") .." "..i18n("system_stats.redis.short_desc_redis_health").." | | Loading... |
\n")
end
print("".. i18n("about.ram_memory") .." "..i18n("system_stats.redis.short_desc_redis_ram_memory").." | ")
print("")
print(ternary(charts_available, "", ""))
print(" | Loading... |
\n")
if not ntop.isWindows() then
print("".. i18n("system_stats.redis.redis_keys") .." "..i18n("system_stats.redis.short_desc_redis_keys").." | ")
print("")
print(ternary(charts_available, "", ""))
print(" | Loading... |
\n")
end
print[[
]]
print("
\n")
elseif(page == "stats") then
print [[
]]
elseif(page == "historical" and charts_available) then
local ts_utils = require("ts_utils")
local schema = _GET["ts_schema"] or "redis:memory"
local selected_epoch = _GET["epoch"] or ""
local tags = {ifid = getSystemInterfaceId(), command = _GET["redis_command"]}
url = url.."&page=historical"
local timeseries = {
{schema = "redis:memory", label = i18n("about.ram_memory")},
{schema = "redis:keys", label = i18n("system_stats.redis.redis_keys")},
{separator=1, label=i18n("system_stats.redis.commands")},
}
-- Populate individual commands timeseries
local series = ts_utils.listSeries("redis:hits", {ifid = getSystemInterfaceId()}, 0)
if(series) then
for _, serie in pairsByField(series, "command", asc) do
timeseries[#timeseries + 1] = {
schema = "redis:hits",
label = i18n("system_stats.redis.command_hits", {cmd = string.upper(string.sub(serie.command, 5))}),
extra_params = {redis_command = serie.command},
metrics_labels = {i18n("graphs.num_calls")},
}
end
end
graph_utils.drawGraphs(getSystemInterfaceId(), schema, tags, _GET["zoom"], url, selected_epoch, {
top_redis_hits = "top:redis:hits",
timeseries = timeseries,
})
end
-- #######################################################
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")