diff options
-rw-r--r-- | health-model.lua | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/health-model.lua b/health-model.lua index 854e2cc..7a25c83 100644 --- a/health-model.lua +++ b/health-model.lua @@ -97,25 +97,22 @@ end get_networkstats = function () local stats = cfe({ type="structure", value={}, label="Network Stats", timestamp=os.time() }) - local result = querycmd("/bin/ip -s link show") + local result = fs.read_file("/proc/net/dev") -- parse the result local i=0 - local intf = "" - for line in string.gmatch(result, "[^\n]*\n?") do - if i==0 then - intf = string.match(line, "^%x+:%s+(%w+):") - if not intf or intf == "" then - break + for line in string.gmatch(result, "[^\n]+\n?") do + if i>1 then + local intf = string.match(line, "([^%s:]+):") + line = string.match(line, ":(.*)$") + local words = {} + for word in string.gmatch(line, "%S+") do + words[#words+1] = word end stats.value[intf] = {} - elseif i==3 then - local bytes, packets = string.match(line, "^%s+(%d+)%s+(%d+)") - stats.value[intf].RX = {bytes=bytes, packets=packets} - elseif i==5 then - local bytes, packets = string.match(line, "^%s+(%d+)%s+(%d+)") - stats.value[intf].TX = {bytes=bytes, packets=packets} + stats.value[intf].RX = {bytes=words[1], packets=words[2]} + stats.value[intf].TX = {bytes=words[9], packets=words[10]} end - i=(i+1)%6 + i=i+1 end return stats end |