diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-09-06 15:11:19 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-09-06 15:11:19 +0000 |
commit | 56a1ef7ebe6ae60bd4722f979ec50684221d94fb (patch) | |
tree | fb3a45b6e1550386d9981027ba68229861dc272d /health-model.lua | |
parent | a02de2a0986b0b4b1f16a56d68488db0c32443b1 (diff) | |
download | acf-alpine-baselayout-56a1ef7ebe6ae60bd4722f979ec50684221d94fb.tar.bz2 acf-alpine-baselayout-56a1ef7ebe6ae60bd4722f979ec50684221d94fb.tar.xz |
Added dynamic network activity page to health controller.
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@1452 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'health-model.lua')
-rw-r--r-- | health-model.lua | 25 |
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 |