net: provide list of available nets

This makes it easier to loop over them and/or handle them separately.
This commit is contained in:
Daniel Hahler 2015-11-01 01:47:31 +01:00
parent 979cc46d80
commit 44452e609f
1 changed files with 2 additions and 1 deletions

View File

@ -28,13 +28,14 @@ local unit = { ["b"] = 1, ["kb"] = 1024,
-- {{{ Net widget type -- {{{ Net widget type
local function worker(format) local function worker(format)
local args = {} local args = { nets = {} }
-- Get NET stats -- Get NET stats
for line in io.lines("/proc/net/dev") do for line in io.lines("/proc/net/dev") do
-- Match wmaster0 as well as rt0 (multiple leading spaces) -- Match wmaster0 as well as rt0 (multiple leading spaces)
local name = string.match(line, "^[%s]?[%s]?[%s]?[%s]?([%w]+):") local name = string.match(line, "^[%s]?[%s]?[%s]?[%s]?([%w]+):")
if name ~= nil then if name ~= nil then
table.insert(args["nets"], name)
-- Received bytes, first value after the name -- Received bytes, first value after the name
local recv = tonumber(string.match(line, ":[%s]*([%d]+)")) local recv = tonumber(string.match(line, ":[%s]*([%d]+)"))
-- Transmited bytes, 7 fields from end of the line -- Transmited bytes, 7 fields from end of the line