summaryrefslogtreecommitdiffstats
path: root/health-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'health-model.lua')
-rw-r--r--health-model.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/health-model.lua b/health-model.lua
index 0646f5e..854e2cc 100644
--- a/health-model.lua
+++ b/health-model.lua
@@ -94,3 +94,28 @@ get_proc = function (self)
proc.memory = cfe({ value=fs.read_file("/proc/meminfo"), label="Memory" })
return cfe({ type="group", value=proc })
end
+
+get_networkstats = function ()
+ local stats = cfe({ type="structure", value={}, label="Network Stats", timestamp=os.time() })
+ local result = querycmd("/bin/ip -s link show")
+ -- 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
+ 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}
+ end
+ i=(i+1)%6
+ end
+ return stats
+end