diff options
author | onefang | 2019-12-12 13:53:47 +1000 |
---|---|---|
committer | onefang | 2019-12-12 13:53:47 +1000 |
commit | beef318bc3f330bb45541e59672f349a6cb5233b (patch) | |
tree | b272b6a0cd311b9987e227c8f7d9c28c7d050527 | |
parent | Re-arrange the RRD data a little. (diff) | |
download | apt-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.
-rw-r--r-- | apt-panopticommon.lua | 77 | ||||
-rwxr-xr-x | apt-panopticon-report-email-web.lua | 24 | ||||
-rwxr-xr-x | apt-panopticon.lua | 12 |
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 |
396 | end | 396 | end |
397 | 397 | ||
398 | APT.fill = function(results) | 398 | APT.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 |
411 | end | 411 | end |
412 | 412 | ||
413 | APT.collate = function(host, ip, results) | 413 | APT.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 |
450 | end | 452 | end |
451 | 453 | APT.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 | ||
477 | end | ||
453 | 478 | ||
454 | 479 | ||
455 | APT.now = 0 | 480 | APT.now = 0 |
@@ -471,7 +496,6 @@ local DSSe = 'DS:URLSanityErrors:GAUGE:' .. hb .. ':0:U' | |||
471 | local DSSw = 'DS:URLSanityWarnings:GAUGE:' .. hb .. ':0:U' | 496 | local DSSw = 'DS:URLSanityWarnings:GAUGE:' .. hb .. ':0:U' |
472 | local DSx = 'DS:max:GAUGE:' .. hb .. ':0:U' | 497 | local DSx = 'DS:max:GAUGE:' .. hb .. ':0:U' |
473 | local DSn = 'DS:min:GAUGE:' .. hb .. ':0:U' | 498 | local DSn = 'DS:min:GAUGE:' .. hb .. ':0:U' |
474 | |||
475 | -- What Collectd uses. | 499 | -- What Collectd uses. |
476 | local RRAc0 = 'RRA:AVERAGE:0.9:1:1200' | 500 | local RRAc0 = 'RRA:AVERAGE:0.9:1:1200' |
477 | local RRAc1 = 'RRA:MIN:0.9:1:1200' | 501 | local RRAc1 = 'RRA:MIN:0.9:1:1200' |
@@ -488,7 +512,6 @@ local RRAc11 = 'RRA:MAX:0.9:223:1202' | |||
488 | local RRAc12 = 'RRA:AVERAGE:0.9:2635:1201' | 512 | local RRAc12 = 'RRA:AVERAGE:0.9:2635:1201' |
489 | local RRAc13 = 'RRA:MIN:0.9:2635:1201' | 513 | local RRAc13 = 'RRA:MIN:0.9:2635:1201' |
490 | local RRAc14 = 'RRA:MAX:0.9:2635:1201' | 514 | local RRAc14 = 'RRA:MAX:0.9:2635:1201' |
491 | |||
492 | -- Try LAST. | 515 | -- Try LAST. |
493 | local RRAl0 = 'RRA:LAST:0.9:1:1200' | 516 | local RRAl0 = 'RRA:LAST:0.9:1:1200' |
494 | local RRAl1 = 'RRA:LAST:0.9:7:1235' | 517 | local RRAl1 = 'RRA:LAST:0.9:7:1235' |
@@ -534,30 +557,12 @@ APT.updateRRD = function(results, host, ip) | |||
534 | end | 557 | end |
535 | end | 558 | end |
536 | 559 | ||
537 | |||
538 | APT.doRRD = function(l, k, v) | 560 | APT.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 | ||
561 | end | 566 | end |
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 |