2021-03-05 17:15:47 +02:00
|
|
|
|
2021-03-19 18:55:17 +02:00
|
|
|
local function get_priority(priority)
|
|
|
|
if priority then
|
|
|
|
priority = tonumber(priority)
|
|
|
|
if priority and QoS.data.queues[priority] then
|
|
|
|
return priority
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function align(s, w)
|
|
|
|
s = tostring(s)
|
|
|
|
return s .. string.rep(' ', w - #s)
|
|
|
|
end
|
|
|
|
|
2021-03-05 17:15:47 +02:00
|
|
|
minetest.register_chatcommand("qos:queue_length", {
|
2021-03-19 19:09:02 +02:00
|
|
|
params = "[<priority>]",
|
2021-03-05 17:15:47 +02:00
|
|
|
description = "Return current QoS queue length",
|
|
|
|
privs = { [QoS.config("info_priv")] = true },
|
|
|
|
func = function(name, priority)
|
2021-03-19 18:55:17 +02:00
|
|
|
priority = get_priority(priority)
|
|
|
|
if priority then
|
|
|
|
minetest.chat_send_player(name, ("QoS current queue length: %d"):format(QoS.queue_length(priority)))
|
|
|
|
elseif priority == false then
|
|
|
|
minetest.chat_send_player(name, "Invalid priority parameter, use empty or 1-"..#QoS.data.queues)
|
|
|
|
else
|
|
|
|
local rows = {}
|
|
|
|
for i,_ in ipairs(QoS.data.queues) do
|
|
|
|
table.insert(rows, (" %s %d%%"):format(align(i, 8), QoS.utilization(i)))
|
|
|
|
end
|
2021-03-19 19:25:32 +02:00
|
|
|
local total = QoS.queue_length()
|
|
|
|
minetest.chat_send_player(name, ("QoS queue length %d in:\n%s"):format(total, table.concat(rows, "\n")))
|
2021-03-19 18:55:17 +02:00
|
|
|
end
|
2021-03-05 17:15:47 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("qos:active_requests", {
|
|
|
|
description = "Return number of active requests executed with QoS controller",
|
|
|
|
privs = { [QoS.config("info_priv")] = true },
|
|
|
|
func = function(name)
|
|
|
|
minetest.chat_send_player(name, ("QoS active requests: %d"):format(QoS.active_requests()))
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("qos:active_utilization", {
|
|
|
|
description = "Return current QoS active requests utilization percentage value",
|
|
|
|
privs = { [QoS.config("info_priv")] = true },
|
2021-03-06 03:10:20 +02:00
|
|
|
func = function(name)
|
2021-03-05 17:15:47 +02:00
|
|
|
minetest.chat_send_player(name, ("QoS active utilization: %d%%"):format(QoS.active_utilization()))
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("qos:utilization", {
|
2021-03-19 19:09:02 +02:00
|
|
|
params = "[<priority>]",
|
2021-03-05 17:15:47 +02:00
|
|
|
description = "Return current QoS queue utilization percentage value",
|
|
|
|
privs = { [QoS.config("info_priv")] = true },
|
|
|
|
func = function(name, priority)
|
2021-03-19 18:55:17 +02:00
|
|
|
priority = get_priority(priority)
|
|
|
|
if priority then
|
|
|
|
minetest.chat_send_player(name, ("QoS queue utilization: %d%%"):format(QoS.utilization(priority)))
|
|
|
|
elseif priority == false then
|
|
|
|
minetest.chat_send_player(name, "Invalid priority parameter, use empty or 1-"..#QoS.data.queues)
|
|
|
|
else
|
|
|
|
local rows = {}
|
|
|
|
for i,_ in ipairs(QoS.data.queues) do
|
|
|
|
table.insert(rows, (" %s %d%%"):format(align(i, 8), QoS.utilization(i)))
|
|
|
|
end
|
2021-03-19 19:25:32 +02:00
|
|
|
local total = QoS.utilization()
|
|
|
|
minetest.chat_send_player(name, ("QoS queue utilization %d%% in:\n%s")
|
|
|
|
:format(total, table.concat(rows, "\n"))
|
|
|
|
)
|
2021-03-19 18:55:17 +02:00
|
|
|
end
|
2021-03-05 17:15:47 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("qos:clear", {
|
2021-03-19 19:09:02 +02:00
|
|
|
params = "<priority>|all",
|
2021-03-19 18:55:17 +02:00
|
|
|
description = "Clear QoS queues by priority, clear all queues if piority is 'all'",
|
2021-03-05 17:15:47 +02:00
|
|
|
privs = { [QoS.config("admin_priv")] = true },
|
|
|
|
func = function(name, priority)
|
2021-03-19 18:55:17 +02:00
|
|
|
if priority == "all" then
|
2021-03-06 17:28:00 +02:00
|
|
|
for i, queue in ipairs(QoS.data.queues) do
|
2021-03-05 17:15:47 +02:00
|
|
|
local length = queue.count
|
|
|
|
queue:clear()
|
2021-03-19 18:55:17 +02:00
|
|
|
minetest.chat_send_player(name, ("QoS cleared %d entries from priority %d"):format(length, i))
|
2021-03-05 17:15:47 +02:00
|
|
|
end
|
2021-03-19 18:55:17 +02:00
|
|
|
elseif get_priority(priority) then
|
|
|
|
priority = get_priority(priority)
|
|
|
|
local length = QoS.data.queues[priority].count
|
|
|
|
QoS.data.queues[priority]:clear()
|
|
|
|
minetest.chat_send_player(name, ("QoS cleared %d entries from priority %d"):format(length, priority))
|
|
|
|
else
|
|
|
|
minetest.chat_send_player(name, "Invalid priority parameter, use 1-"..#QoS.data.queues.." or 'all'")
|
2021-03-05 17:15:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|