aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authoronefang2019-12-12 13:53:47 +1000
committeronefang2019-12-12 13:53:47 +1000
commitbeef318bc3f330bb45541e59672f349a6cb5233b (patch)
treeb272b6a0cd311b9987e227c8f7d9c28c7d050527
parentRe-arrange the RRD data a little. (diff)
downloadapt-panopticon-beef318bc3f330bb45541e59672f349a6cb5233b.zip
apt-panopticon-beef318bc3f330bb45541e59672f349a6cb5233b.tar.gz
apt-panopticon-beef318bc3f330bb45541e59672f349a6cb5233b.tar.bz2
apt-panopticon-beef318bc3f330bb45541e59672f349a6cb5233b.tar.xz
Some refactoring of the results data handling.
Diffstat (limited to '')
-rw-r--r--apt-panopticommon.lua77
-rwxr-xr-xapt-panopticon-report-email-web.lua24
-rwxr-xr-xapt-panopticon.lua12
3 files changed, 44 insertions, 69 deletions
diff --git a/apt-panopticommon.lua b/apt-panopticommon.lua
index 5c0dfe3..aba2a2a 100644
--- a/apt-panopticommon.lua
+++ b/apt-panopticommon.lua
@@ -395,7 +395,7 @@ APT.plurals = function(e, w)
395 return result 395 return result
396end 396end
397 397
398APT.fill = function(results) 398APT.padResults = function(results)
399 for k, v in pairs{"ftp", "http", "https", "rsync"} do 399 for k, v in pairs{"ftp", "http", "https", "rsync"} do
400 tests = results[v] 400 tests = results[v]
401 if nil == tests then tests = {errors = 0; warnings = 0} end 401 if nil == tests then tests = {errors = 0; warnings = 0} end
@@ -410,14 +410,12 @@ APT.fill = function(results)
410 return results 410 return results
411end 411end
412 412
413APT.collate = function(host, ip, results) 413APT.collate = function(l, host, ip, results)
414 results = APT.fill(results) 414 results = APT.padResults(results)
415 local f = "results/" .. host .. "_" .. ip .. ".lua" 415 local f = l .. "/" .. host .. "_" .. ip .. ".lua"
416 local rfile, e = io.open(f, "r") 416 if APT.checkFile(f) then
417 if nil == rfile then I("opening " .. f .. " file - " .. e) else
418 rfile:close()
419 local rs = loadfile(f)() 417 local rs = loadfile(f)()
420 rs = APT.fill(rs) 418 rs = APT.padResults(rs)
421 for k, v in pairs(rs) do 419 for k, v in pairs(rs) do
422 if "table" == type(v) then 420 if "table" == type(v) then
423 if ("speed" == k) and (nil ~= results.speed) then 421 if ("speed" == k) and (nil ~= results.speed) then
@@ -427,7 +425,11 @@ APT.collate = function(host, ip, results)
427 for i, u in pairs(v) do 425 for i, u in pairs(v) do
428 if "table" == type(u) then 426 if "table" == type(u) then
429 for h, t in pairs(u) do 427 for h, t in pairs(u) do
430 local a = results[k][i][h] 428 local a = results[k]
429 if nil == a then results[k] = {i = {}}; a = results[k] end
430 a = a[i]
431 if nil == a then results[k][i] = {h = {}}; a = results[k][i] end
432 a = a[h]
431 if nil == a then a = 0 end 433 if nil == a then a = 0 end
432 results[k][i][h] = a + t 434 results[k][i][h] = a + t
433 end 435 end
@@ -448,8 +450,31 @@ APT.collate = function(host, ip, results)
448 end 450 end
449 return results 451 return results
450end 452end
451 453APT.collateAll = function(l, host, func)
452 454 results = {}
455 local f = l .. "/" .. host .. ".lua"
456 if APT.checkFile(f) then
457 results = loadfile(f)()
458 results = APT.padResults(results)
459 if nil ~= func then func(results) end
460 local v = APT.mirrors[host]
461 if nil ~= v then
462 local IPs = v.IPs
463 for i, u in pairs(IPs) do
464 if "table" == type(u) then
465 for h, t in pairs(u) do
466 results = APT.collate(l, host, h, results)
467 if nil ~= func then func(results, h) end
468 end
469 else
470 results = APT.collate(l, host, i, results)
471 if nil ~= func then func(results, i) end
472 end
473 end
474 end
475 end
476 return results
477end
453 478
454 479
455APT.now = 0 480APT.now = 0
@@ -471,7 +496,6 @@ local DSSe = 'DS:URLSanityErrors:GAUGE:' .. hb .. ':0:U'
471local DSSw = 'DS:URLSanityWarnings:GAUGE:' .. hb .. ':0:U' 496local DSSw = 'DS:URLSanityWarnings:GAUGE:' .. hb .. ':0:U'
472local DSx = 'DS:max:GAUGE:' .. hb .. ':0:U' 497local DSx = 'DS:max:GAUGE:' .. hb .. ':0:U'
473local DSn = 'DS:min:GAUGE:' .. hb .. ':0:U' 498local DSn = 'DS:min:GAUGE:' .. hb .. ':0:U'
474
475-- What Collectd uses. 499-- What Collectd uses.
476local RRAc0 = 'RRA:AVERAGE:0.9:1:1200' 500local RRAc0 = 'RRA:AVERAGE:0.9:1:1200'
477local RRAc1 = 'RRA:MIN:0.9:1:1200' 501local RRAc1 = 'RRA:MIN:0.9:1:1200'
@@ -488,7 +512,6 @@ local RRAc11 = 'RRA:MAX:0.9:223:1202'
488local RRAc12 = 'RRA:AVERAGE:0.9:2635:1201' 512local RRAc12 = 'RRA:AVERAGE:0.9:2635:1201'
489local RRAc13 = 'RRA:MIN:0.9:2635:1201' 513local RRAc13 = 'RRA:MIN:0.9:2635:1201'
490local RRAc14 = 'RRA:MAX:0.9:2635:1201' 514local RRAc14 = 'RRA:MAX:0.9:2635:1201'
491
492-- Try LAST. 515-- Try LAST.
493local RRAl0 = 'RRA:LAST:0.9:1:1200' 516local RRAl0 = 'RRA:LAST:0.9:1:1200'
494local RRAl1 = 'RRA:LAST:0.9:7:1235' 517local RRAl1 = 'RRA:LAST:0.9:7:1235'
@@ -534,30 +557,12 @@ APT.updateRRD = function(results, host, ip)
534 end 557 end
535end 558end
536 559
537
538APT.doRRD = function(l, k, v) 560APT.doRRD = function(l, k, v)
539 if APT.checkFile(l .. "/" .. k .. ".lua") then 561 APT.collateAll(l, k,
540 local results = loadfile(l .. "/" .. k .. ".lua")() 562 function(results, ip)
541 results = APT.fill(results) 563 APT.createRRD(k, ip)
542 APT.createRRD(k) 564 APT.updateRRD(results, k, ip)
543 APT.updateRRD(results, k) 565 end)
544 if nil ~= v then
545 local IPs = v.IPs
546 for i, u in pairs(IPs) do
547 if "table" == type(u) then
548 for h, t in pairs(u) do
549 APT.createRRD(k, h)
550 results = APT.collate(k, h, results)
551 APT.updateRRD(results, k, h)
552 end
553 else
554 APT.createRRD(k, i)
555 results = APT.collate(k, i, results)
556 APT.updateRRD(results, k, i)
557 end
558 end
559 end
560 end
561end 566end
562 567
563 568
diff --git a/apt-panopticon-report-email-web.lua b/apt-panopticon-report-email-web.lua
index 6319d1e..c19d211 100755
--- a/apt-panopticon-report-email-web.lua
+++ b/apt-panopticon-report-email-web.lua
@@ -160,18 +160,8 @@ if nil == email then C("opening mirrors file - " .. e) else
160 "==== package mirror status " .. os.date("!%Y-%m-%d %H:%M") .. " GMT ====\n" .. 160 "==== package mirror status " .. os.date("!%Y-%m-%d %H:%M") .. " GMT ====\n" ..
161 "[skip] means that the test hasn't been written yet.\n\n") 161 "[skip] means that the test hasn't been written yet.\n\n")
162 for k, v in APT.orderedPairs(APT.mirrors) do 162 for k, v in APT.orderedPairs(APT.mirrors) do
163 local results = loadfile("results/" .. k .. ".lua")()
164 email:write(k .. "....\n") 163 email:write(k .. "....\n")
165 local IPs = v.IPs 164 local results = APT.collateAll('results', k)
166 for i, u in pairs(IPs) do
167 if "table" == type(u) then
168 for h, t in pairs(u) do
169 results = APT.collate(k, h, results)
170 end
171 else
172 results = APT.collate(k, i, results)
173 end
174 end
175 local ftp = "[skip]" 165 local ftp = "[skip]"
176 local http = status(k, results, "http") 166 local http = status(k, results, "http")
177 local https = status(k, results, "https") 167 local https = status(k, results, "https")
@@ -325,7 +315,7 @@ if nil == web then C("opening mirrors file - " .. e) else
325 "<th>Protocol</th><th>URL sanity</th><th>Integrity</th><th>Updated</th><th colspan='2'>Speed range</th></tr>\n" 315 "<th>Protocol</th><th>URL sanity</th><th>Integrity</th><th>Updated</th><th colspan='2'>Speed range</th></tr>\n"
326 ) 316 )
327 for k, v in APT.orderedPairs(APT.mirrors) do 317 for k, v in APT.orderedPairs(APT.mirrors) do
328 local results = loadfile("results/" .. k .. ".lua")() 318 local results = APT.collateAll('results', k)
329 local active = "" 319 local active = ""
330 if "yes" == v.Active then 320 if "yes" == v.Active then
331 web:write(" <tr><th>" .. k .. "</th> ") 321 web:write(" <tr><th>" .. k .. "</th> ")
@@ -333,16 +323,6 @@ if nil == web then C("opening mirrors file - " .. e) else
333 if nil == v.Active then active = 'nil' else active = v.Active end 323 if nil == v.Active then active = 'nil' else active = v.Active end
334 web:write(" <tr style='background-color:dimgrey'><th>" .. k .. "</th> ") 324 web:write(" <tr style='background-color:dimgrey'><th>" .. k .. "</th> ")
335 end 325 end
336 local IPs = v.IPs
337 for i, u in pairs(IPs) do
338 if "table" == type(u) then
339 for h, t in pairs(u) do
340 results = APT.collate(k, h, results)
341 end
342 else
343 results = APT.collate(k, i, results)
344 end
345 end
346 local ftp = "[<font color='grey'><b>skip</b></font>]" 326 local ftp = "[<font color='grey'><b>skip</b></font>]"
347 local http = status(k, results, "http") 327 local http = status(k, results, "http")
348 local https = status(k, results, "https") 328 local https = status(k, results, "https")
diff --git a/apt-panopticon.lua b/apt-panopticon.lua
index c5b76b3..cd3b38e 100755
--- a/apt-panopticon.lua
+++ b/apt-panopticon.lua
@@ -654,17 +654,7 @@ if 0 < #arg then
654 APT.mirrors = loadfile("results/mirrors.lua")() 654 APT.mirrors = loadfile("results/mirrors.lua")()
655 if nil ~= arg[2] then I(" Using IP " .. arg[2]); ip = arg[2] end 655 if nil ~= arg[2] then I(" Using IP " .. arg[2]); ip = arg[2] end
656 if nil ~= arg[3] then I(" Using file " .. arg[3]); end 656 if nil ~= arg[3] then I(" Using file " .. arg[3]); end
657 657 APT.results = APT.padResults(APT.results)
658 for k, v in pairs{"ftp", "http", "https", "rsync"} do
659 if APT.testing(v) then
660 local tests = {errors = 0; warnings = 0}
661 if APT.testing("Integrity") then tests.Integrity = {errors = 0; warnings = 0} end
662 if APT.testing("Protocol") then tests.Protocol = {errors = 0; warnings = 0} end
663 if APT.testing("Updated") then tests.Updated = {errors = 0; warnings = 0} end
664 if APT.testing("URLSanity") then tests.URLSanity = {errors = 0; warnings = 0} end
665 APT.results[v] = tests
666 end
667 end
668 if APT.origin then 658 if APT.origin then
669 if APT.testing("Integrity") or APT.testing("Updated") then 659 if APT.testing("Integrity") or APT.testing("Updated") then
670 if APT.origin and (APT.options.roundRobin.value ~= pu.host) then 660 if APT.origin and (APT.options.roundRobin.value ~= pu.host) then