From 56a1ef7ebe6ae60bd4722f979ec50684221d94fb Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Sat, 6 Sep 2008 15:11:19 +0000 Subject: 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 --- health-model.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'health-model.lua') 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 -- cgit v1.2.3