dio: further improved support for multiple devices
This commit is contained in:
parent
8fe4cf436a
commit
71566e0484
30
dio.lua
30
dio.lua
|
@ -34,41 +34,41 @@ end
|
|||
|
||||
-- {{{ Disk I/O widget type
|
||||
local function worker(format, disk)
|
||||
local disk_lines = { disk = {} }
|
||||
local disk_lines = { [disk] = {} }
|
||||
local disk_stats = helpers.pathtotable("/sys/block/" .. disk)
|
||||
|
||||
if disk_stats.stat then
|
||||
local match = string.gmatch(disk_stats.stat, "[%s]+([%d]+)")
|
||||
for i = 1, 11 do -- Store disk stats
|
||||
table.insert(disk_lines.disk, match())
|
||||
table.insert(disk_lines[disk], match())
|
||||
end
|
||||
end
|
||||
|
||||
-- Ensure tables are initialized correctly
|
||||
local diff_total = { disk = {} }
|
||||
if not disk_total.disk then
|
||||
disk_usage.disk = {}
|
||||
disk_total.disk = {}
|
||||
local diff_total = { [disk] = {} }
|
||||
if not disk_total[disk] then
|
||||
disk_usage[disk] = {}
|
||||
disk_total[disk] = {}
|
||||
|
||||
while #disk_total.disk < #disk_lines.disk do
|
||||
table.insert(disk_total.disk, 0)
|
||||
while #disk_total[disk] < #disk_lines[disk] do
|
||||
table.insert(disk_total[disk], 0)
|
||||
end
|
||||
end
|
||||
|
||||
for i, v in ipairs(disk_lines.disk) do
|
||||
for i, v in ipairs(disk_lines[disk]) do
|
||||
-- Diskstats are absolute, substract our last reading
|
||||
diff_total.disk[i] = v - disk_total.disk[i]
|
||||
diff_total[disk][i] = v - disk_total[disk][i]
|
||||
|
||||
-- Store totals
|
||||
disk_total.disk[i] = v
|
||||
disk_total[disk][i] = v
|
||||
end
|
||||
|
||||
-- Calculate and store I/O
|
||||
uformat(disk_usage.disk, "read", diff_total.disk[3])
|
||||
uformat(disk_usage.disk, "write", diff_total.disk[7])
|
||||
uformat(disk_usage.disk, "total", diff_total.disk[7] + diff_total.disk[3])
|
||||
uformat(disk_usage[disk], "read", diff_total[disk][3])
|
||||
uformat(disk_usage[disk], "write", diff_total[disk][7])
|
||||
uformat(disk_usage[disk], "total", diff_total[disk][7] + diff_total[disk][3])
|
||||
|
||||
return disk_usage.disk
|
||||
return disk_usage[disk]
|
||||
end
|
||||
-- }}}
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ local function worker(format, warg)
|
|||
local f = io.open(warg[i])
|
||||
|
||||
while true do
|
||||
-- Read the mbox line by line, if we are going to read some
|
||||
-- *HUGE* folders then switch to reading chunks
|
||||
-- Read the mbox line by line, if we are going to read
|
||||
-- some *HUGE* folders then switch to reading chunks
|
||||
local lines = f:read("*line")
|
||||
if not lines then break end
|
||||
|
||||
|
|
4
wifi.lua
4
wifi.lua
|
@ -41,8 +41,8 @@ local function worker(format, iface)
|
|||
return winfo
|
||||
end
|
||||
|
||||
-- The output differs from system to system, some stats can
|
||||
-- be separated by =, and not all drivers report all stats
|
||||
-- Output differs from system to system, some stats can be
|
||||
-- separated by =, and not all drivers report all stats
|
||||
winfo["{ssid}"] = -- SSID can have almost anything in it
|
||||
string.match(iw, 'ESSID[=:]"([%w%p]+[%s]*[%w%p]*]*)"') or winfo["{ssid}"]
|
||||
winfo["{mode}"] = -- Modes are simple, but also match the "-" in Ad-Hoc
|
||||
|
|
Loading…
Reference in New Issue