From 73808f2d16a80c350ba420a5d88823e0be509b1b Mon Sep 17 00:00:00 2001 From: onefang Date: Fri, 27 Dec 2019 13:53:50 +1000 Subject: Add timeouts tracking. --- apt-panopticommon.lua | 40 +++++++++++++++++++++++++++------------- apt-panopticon-update-data.lua | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 14 deletions(-) diff --git a/apt-panopticommon.lua b/apt-panopticommon.lua index 71e9a9c..e35201d 100644 --- a/apt-panopticommon.lua +++ b/apt-panopticommon.lua @@ -491,17 +491,27 @@ APT.plurals = function(e, w, t) return result end +local typs = {'errors', 'warnings', 'timeouts'} APT.padResults = function(results) local c = 0 if nil == results then results = {}; c = 999 end for k, v in pairs(APT.protocols) do tests = results[v] - if nil == tests then tests = {errors = c; warnings = c; timeouts = c} end - if nil == tests.Integrity then tests.Integrity = {errors = c; warnings = c; timeouts = c} end - if nil == tests.Protocol then tests.Protocol = {errors = c; warnings = c; timeouts = c} end - if nil == tests.Updated then tests.Updated = {errors = c; warnings = c; timeouts = c} end - if nil == tests.redirects then tests.redirects = {} end - if nil == tests.URLSanity then tests.URLSanity = {errors = c; warnings = c; timeouts = c} end + if nil == tests then tests = {} end + for m, x in pairs(typs) do + if nil == tests[x] then tests[x] = c end + end + for l, w in pairs(APT.tests) do + if ('raw' ~= w) and ('Speed' ~= w) then + if nil == tests[w] then tests[w] = {} end + for m, x in pairs(typs) do + if nil == tests[w][x] then tests[w][x] = c end + end + end + end + if nil == tests.redirects then + tests.redirects = {} + end results[v] = tests end if nil == results.timeout then results.timeout = false end @@ -589,12 +599,16 @@ local step = '10min' local hb = '150min' local DSIe = 'DS:IntegrityErrors:GAUGE:' .. hb .. ':0:U' local DSIw = 'DS:IntegrityWarnings:GAUGE:' .. hb .. ':0:U' +local DSIt = 'DS:IntegrityTimeouts:GAUGE:' .. hb .. ':0:U' local DSPe = 'DS:ProtocolErrors:GAUGE:' .. hb .. ':0:U' local DSPw = 'DS:ProtocolWarnings:GAUGE:' .. hb .. ':0:U' +local DSPt = 'DS:ProtocolTimeouts:GAUGE:' .. hb .. ':0:U' local DSUe = 'DS:UpdatedErrors:GAUGE:' .. hb .. ':0:U' local DSUw = 'DS:UpdatedWarnings:GAUGE:' .. hb .. ':0:U' +local DSUt = 'DS:UpdatedTimeouts:GAUGE:' .. hb .. ':0:U' local DSSe = 'DS:URLSanityErrors:GAUGE:' .. hb .. ':0:U' local DSSw = 'DS:URLSanityWarnings:GAUGE:' .. hb .. ':0:U' +local DSSt = 'DS:URLSanityTimeouts:GAUGE:' .. hb .. ':0:U' local DSx = 'DS:max:GAUGE:' .. hb .. ':0:U' local DSn = 'DS:min:GAUGE:' .. hb .. ':0:U' -- What Collectd uses. @@ -627,10 +641,10 @@ APT.createRRD = function(host, ip, o) os.execute( 'mkdir -p rrd/' .. host .. '/' .. p:upper()) if not APT.checkFile('rrd/' .. host .. '/' .. p:upper() .. '/Tests.rrd') then D('Creating ' .. 'rrd/' .. host .. '/' .. p:upper() .. '/Tests.rrd') - APT.rrd.create( 'rrd/' .. host .. '/' .. p:upper() .. '/Tests.rrd', '--start', start, '--step', step, DSIe, DSIw, DSPe, DSPw, DSUe, DSUw, DSSe, DSSw, + APT.rrd.create( 'rrd/' .. host .. '/' .. p:upper() .. '/Tests.rrd', '--start', start, '--step', step, DSIe, DSIw, DSIt, DSPe, DSPw, DSPt, DSUe, DSUw, DSUt, DSSe, DSSw, DSSt, RRAc0, RRAc1, RRAc2, RRAl0, RRAc3, RRAc4, RRAc5, RRAl1, RRAc6, RRAc7, RRAc8, RRAl2, RRAc9, RRAc10, RRAc11, RRAl3, RRAc12, RRAc13, RRAc14, RRAl4) -- Start them at 0 so the average has something to work on. - APT.rrd.update( 'rrd/' .. host .. '/' .. p:upper() .. '/Tests.rrd', (APT.now - 600) .. ':0:0:0:0:0:0:0:0') + APT.rrd.update( 'rrd/' .. host .. '/' .. p:upper() .. '/Tests.rrd', (APT.now - 600) .. ':0:0:0:0:0:0:0:0:0:0:0:0') end end os.execute( 'mkdir -p rrd/' .. host .. '/Speed') @@ -647,12 +661,12 @@ APT.updateRRD = function(results, host, ip) for i, p in pairs(APT.protocols) do if nil ~= results[p] then APT.rrd.update('rrd/' .. host .. '/' .. p:upper() .. '/Tests.rrd', APT.now .. ':' .. - results[p]['Integrity'].errors .. ':' .. results[p]['Integrity'].warnings .. ':' .. - results[p]['Protocol'].errors .. ':' .. results[p]['Protocol'].warnings .. ':' .. - results[p]['Updated'].errors .. ':' .. results[p]['Updated'].warnings .. ':' .. - results[p]['URLSanity'].errors .. ':' .. results[p]['URLSanity'].warnings) + results[p]['Integrity'].errors .. ':' .. results[p]['Integrity'].warnings .. ':' .. results[p]['Integrity'].timeouts .. ':' .. + results[p]['Protocol'].errors .. ':' .. results[p]['Protocol'].warnings .. ':' .. results[p]['Protocol'].timeouts .. ':' .. + results[p]['Updated'].errors .. ':' .. results[p]['Updated'].warnings .. ':' .. results[p]['Updated'].timeouts .. ':' .. + results[p]['URLSanity'].errors .. ':' .. results[p]['URLSanity'].warnings .. ':' .. results[p]['URLSanity'].timeouts) else - APT.rrd.update('rrd/' .. host .. '/' .. p:upper() .. '/Tests.rrd', APT.now .. ':U:U:U:U:U:U:U:U') + APT.rrd.update('rrd/' .. host .. '/' .. p:upper() .. '/Tests.rrd', APT.now .. ':U:U:U:U:U:U:U:U:U:U:U:U') end end if nil ~= results.speed then diff --git a/apt-panopticon-update-data.lua b/apt-panopticon-update-data.lua index 57eddd9..ceef7f3 100755 --- a/apt-panopticon-update-data.lua +++ b/apt-panopticon-update-data.lua @@ -11,6 +11,35 @@ local arg, sendArgs = APT.parseArgs({...}) local oldest = 0 +local fixResults = function(f) + if APT.checkFile(f) then + local results = loadfile(f)() + results = APT.padResults(results) + for i, w in pairs(APT.protocols) do + tests = results[w] + if nil ~= tests.Redirects then + tests.redirects = tests.Redirects + tests.Redirects = nil + elseif nil == tests.redirects then + tests.redirects = {} + end + results[w] = tests + end + if nil ~= results.Redirects then + for i, w in pairs(APT.protocols) do + results[w].redirects = results.Redirects + end + results.Redirects = nil + end + local rfile, e = io.open(f, "w+") + if nil == rfile then C("opening results file - " .. e) else + rfile:write(APT.dumpTable(results, "", "results") .. "\nreturn results\n") + rfile:close() + end + end +end + + local lock = 'apt-panopticon.lock' while APT.checkFile(lock) do os.execute('sleep 10') end os.execute('touch ' .. lock) @@ -53,7 +82,6 @@ for l in files:lines() do local f = l:sub(1, -8) .. "/" .. k .. ".lua" if APT.checkFile(f) then results = loadfile(f)() - results = APT.padResults(results) results['IPs'] = v.IPs local rfile, e = io.open(f, "w+") if nil == rfile then C("opening results file - " .. e) else @@ -63,6 +91,10 @@ for l in files:lines() do end end end + local fls = io.popen('ls -1 ' .. lsub .. '/*.lua 2>/dev/null') + for k in fls:lines() do + fixResults(k) + end end -- cgit v1.1