Added 24H Availability

This commit is contained in:
Luca Deri 2020-04-23 18:33:45 +02:00
parent 7bd499adb9
commit 069268fc15
5 changed files with 37 additions and 3 deletions

View file

@ -165,17 +165,39 @@ function am_utils.getAvailability(host, measurement)
local tot_available = 0
local tot_unavailable = 0
local rc = '<svg width="240" height="15">'
local time = os.date("*t")
for i=1,24 do
local pt = hour_stats.hstats[i]
if pt then
tot_available = tot_available + pt[HOUR_STATS_OK]
tot_unavailable = tot_unavailable + pt[HOUR_STATS_EXCEEDED] + pt[HOUR_STATS_UNREACHABLE]
if((pt[HOUR_STATS_OK]+pt[HOUR_STATS_UNREACHABLE]+pt[HOUR_STATS_EXCEEDED]) == 0) then
color = 'lightgray'
elseif((pt[HOUR_STATS_UNREACHABLE]+pt[HOUR_STATS_EXCEEDED]) == 0) then
color = '#28a745'
elseif(((pt[HOUR_STATS_UNREACHABLE]+pt[HOUR_STATS_EXCEEDED]) > 0) and (pt[HOUR_STATS_OK] == 0)) then
color = 'red'
else
color = '#ffc107'
end
if((i-1) == time.hour) then
stroke = ';stroke-width:1;stroke:rgb(0,0,0)'
else
stroke = ''
end
rc = rc ..' <rect x="'.. ((i-1)*8) ..'" y="0" width="5" height="15" style="fill:'..color.. stroke..'" />'
end
end
return(tot_available * 100 / (tot_available + tot_unavailable))
rc = rc .. '</svg>'
return rc, (tot_available * 100 / (tot_available + tot_unavailable))
end
-- ##############################################