aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apt-panopticommon.lua
diff options
context:
space:
mode:
authoronefang2019-12-12 13:53:47 +1000
committeronefang2019-12-12 13:53:47 +1000
commitbeef318bc3f330bb45541e59672f349a6cb5233b (patch)
treeb272b6a0cd311b9987e227c8f7d9c28c7d050527 /apt-panopticommon.lua
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 'apt-panopticommon.lua')
-rw-r--r--apt-panopticommon.lua77
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
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