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 /apt-panopticommon.lua | |
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.
Diffstat (limited to 'apt-panopticommon.lua')
-rw-r--r-- | apt-panopticommon.lua | 77 |
1 files changed, 41 insertions, 36 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 | ||