From daca02cdef0abe2557b7a6a2abae82a159116157 Mon Sep 17 00:00:00 2001 From: onefang Date: Wed, 4 Dec 2019 08:14:16 +1000 Subject: Move the speed calc to the main script. --- apt-panopticon-report-email-web.lua | 45 ++++++++++++++----------------------- apt-panopticon.lua | 21 +++++++++++++++++ 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/apt-panopticon-report-email-web.lua b/apt-panopticon-report-email-web.lua index 03970ac..9e9d818 100755 --- a/apt-panopticon-report-email-web.lua +++ b/apt-panopticon-report-email-web.lua @@ -244,17 +244,22 @@ local collate = function(host, ip, results) local rs = loadfile(f)() for k, v in pairs(rs) do if "table" == type(v) then - for i, u in pairs(v) do - if "table" == type(u) then - for h, t in pairs(u) do - local a = results[k][h] + if "speed" == k then + if v.min < results.speed.min then results.speed.min = v.min end + if v.max > results.speed.max then results.speed.max = v.max end + else + for i, u in pairs(v) do + if "table" == type(u) then + for h, t in pairs(u) do + local a = results[k][h] + if nil == a then a = 0 end + results[k][h] = a + t + end + else + local a = results[k][i] if nil == a then a = 0 end - results[k][h] = a + t + results[k][i] = a + u end - else - local a = results[k][i] - if nil == a then a = 0 end - results[k][i] = a + u end end else @@ -445,7 +450,9 @@ if nil == web then C("opening mirrors file - " .. e) else local updated = status(k, results, "Updated") local rate = v.Rate if nil ~= rate then updated = updated .. ' ' .. rate end - local min, max, spd = 999999999999, 0, '' + local min = tonumber(results.speed.min) + local max = tonumber(results.speed.max) + local spd = '' -- DNS-RR test. if ("deb.devuan.org" ~= k) and (nil ~= mirrors["deb.devuan.org"]) then @@ -476,25 +483,7 @@ if nil == web then C("opening mirrors file - " .. e) else end end end - if "" == dns then dns = "[no]" end - for i, mt in pairs({'Release', 'Packages', 'META'}) do - if checkFile("results/curl-" .. mt .. "-" .. k .. ".log") then - for l in io.lines("results/curl-" .. mt .. "-" .. k .. ".log") do - local speed, crrnt = l:match('^%c *%d+ +%d+k? +%d+ +%d+k? +%d+ +%d+ +(%d+k?) +%d+ +[%d%-]+:[%d%-]+:[%d%-]+ +[%d%-]+:[%d%-]+:[%d%-]+ +[%d%-]+:[%d%-]+:[%d%-]+ +(%d+k?)') - if nil ~= speed then - if 'k' == speed:sub(-1, -1) then speed = speed:sub(1, -2) .. '000' end - if 'k' == crrnt:sub(-1, -1) then crrnt = crrnt:sub(1, -2) .. '000' end - speed = tonumber(speed) - crrnt = tonumber(crrnt) - if speed < min and speed ~= 0 then min = speed end - if speed > max then max = speed end - if crrnt < min and crrnt ~= 0 then min = crrnt end - if crrnt > max then max = crrnt end - end - end - end - end if 0 == max then spd = '' else diff --git a/apt-panopticon.lua b/apt-panopticon.lua index 7da7380..5aa1e8d 100755 --- a/apt-panopticon.lua +++ b/apt-panopticon.lua @@ -1073,6 +1073,27 @@ if 0 < #arg then if not keep then os.execute("rm -fr results/" .. pu.host) end os.execute('rm STATUS_' .. pu.host .. '* 2>/dev/null') end + + local min, max, spd = 999999999999, 0 + for i, mt in pairs({'Release', 'Packages', 'META'}) do + if checkFile("results/curl-" .. mt .. "-" .. pu.host .. ".log") then + for l in io.lines("results/curl-" .. mt .. "-" .. pu.host .. ".log") do + local speed, crrnt = l:match('^%c *%d+ +%d+k? +%d+ +%d+k? +%d+ +%d+ +(%d+k?) +%d+ +[%d%-]+:[%d%-]+:[%d%-]+ +[%d%-]+:[%d%-]+:[%d%-]+ +[%d%-]+:[%d%-]+:[%d%-]+ +(%d+k?)') + if nil ~= speed then + if 'k' == speed:sub(-1, -1) then speed = speed:sub(1, -2) .. '000' end + if 'k' == crrnt:sub(-1, -1) then crrnt = crrnt:sub(1, -2) .. '000' end + speed = tonumber(speed) + crrnt = tonumber(crrnt) + if speed < min and speed ~= 0 then min = speed end + if speed > max then max = speed end + if crrnt < min and crrnt ~= 0 then min = crrnt end + if crrnt > max then max = crrnt end + end + end + end + end + results["speed"] = {min = min, max = max} + local f = pu.host if "" ~= ip then f = f .. "_" .. ip end local rfile, e = io.open("results/" .. f .. ".lua", "w+") -- cgit v1.1