net: sanitize time computation to avoid division by zero
This commit is contained in:
parent
d2a00d7057
commit
8fe4cf436a
14
net.lua
14
net.lua
|
@ -57,19 +57,19 @@ local function worker(format)
|
||||||
-- Default values on the first run
|
-- Default values on the first run
|
||||||
nets[name] = {}
|
nets[name] = {}
|
||||||
uformat(args, name .. " down", 0)
|
uformat(args, name .. " down", 0)
|
||||||
uformat(args, name .. " up", 0)
|
uformat(args, name .. " up", 0)
|
||||||
|
|
||||||
nets[name].time = os.time()
|
nets[name].time = os.time()
|
||||||
else
|
else -- Net stats are absolute, substract our last reading
|
||||||
-- Net stats are absolute, substract our last reading
|
local interval = os.time() - nets[name].time > 0 and
|
||||||
local interval = os.time() - nets[name].time
|
os.time() - nets[name].time or 1
|
||||||
nets[name].time = os.time()
|
nets[name].time = os.time()
|
||||||
|
|
||||||
local down = (recv - nets[name][1])/interval
|
local down = (recv - nets[name][1]) / interval
|
||||||
local up = (send - nets[name][2])/interval
|
local up = (send - nets[name][2]) / interval
|
||||||
|
|
||||||
uformat(args, name .. " down", down)
|
uformat(args, name .. " down", down)
|
||||||
uformat(args, name .. " up", up)
|
uformat(args, name .. " up", up)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Store totals
|
-- Store totals
|
||||||
|
|
Loading…
Reference in New Issue