-- Astra Stream : HTTP connections list
-- Usage:
-- 1. Save script into the file: /etc/astra/stat.lua
-- 2. Launch astra: astra --stream /etc/astra/stat.lua /etc/astra/config.lua
-- 3. Access to the stat in browser: http://server-address:5000/
local http_stat_port = 5000
--
function render_stat_html()
local table_content = ""
local i = 1
local ct = os.time()
for _, http_instance in pairs(http_output_instance_list) do
for channel_path, output_data in pairs(http_instance.__options.channel_list) do
for _, client_data in pairs(output_data.client_list) do
local dt = ct - client_data.st
local uptime = string.format("%02d:%02d", (dt / 3600), (dt / 60) % 60)
table_content = table_content ..
"
" ..
"| " .. i .. " | " ..
"" .. client_data.addr .. " | " ..
"" .. client_data.path .. " | " ..
"" .. uptime .. " | " ..
"
\r\n"
i = i + 1
end
end
end
return [[
Astra Stream : Statistics
| Astra Stream |
Astra v.]] .. astra.version .. [[ |
| # |
IP |
Source |
Uptime |
]] .. table_content .. [[
]]
end
function on_request_stat(server, client, request)
if not request then
return nil
end
server:send(client, {
code = 200,
headers = {
"Content-Type: text/html; charset=utf-8",
"Connection: close",
},
content = render_stat_html(),
})
end
http_server({
addr = "0.0.0.0",
port = http_stat_port,
route = {
{ "/", on_request_stat },
},
})