FIX make readwrite query all my devices
This commit is contained in:
parent
269edfdd65
commit
031f9b9881
|
@ -5,6 +5,14 @@ local Geometry = require 'Geometry'
|
||||||
return function(update_freq)
|
return function(update_freq)
|
||||||
local PLOT_SEC_BREAK = 20
|
local PLOT_SEC_BREAK = 20
|
||||||
local PLOT_HEIGHT = 56
|
local PLOT_HEIGHT = 56
|
||||||
|
local DEVICES = {'sda', 'nvme0n1'}
|
||||||
|
|
||||||
|
-- the sector size of any block device in linux is 512 bytes
|
||||||
|
-- see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/types.h?id=v4.4-rc6#n121
|
||||||
|
local BLOCK_SIZE_BYTES = 512
|
||||||
|
|
||||||
|
-- fields 3 and 7 (sectors read and written)
|
||||||
|
local RW_REGEX = '%s+%d+%s+%d+%s+(%d+)%s+%d+%s+%d+%s+%d+%s+(%d+)'
|
||||||
|
|
||||||
local __tonumber = tonumber
|
local __tonumber = tonumber
|
||||||
local __string_match = string.match
|
local __string_match = string.match
|
||||||
|
@ -61,21 +69,25 @@ return function(update_freq)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
-- update function
|
-- update function
|
||||||
|
|
||||||
-- TODO add more devices to this
|
local DEVICE_PATHS = {}
|
||||||
local BLOCK_SIZE_BYTES = 512
|
for i = 1, #DEVICES do
|
||||||
local STAT_FILE = '/sys/block/sda/stat'
|
DEVICE_PATHS[i] = string.format('/sys/block/%s/stat', DEVICES[i])
|
||||||
|
end
|
||||||
|
|
||||||
-- fields 3 and 7 (sectors read and written)
|
local read_devices = function()
|
||||||
local RW_REGEX = '%s+%d+%s+%d+%s+(%d+)%s+%d+%s+%d+%s+%d+%s+(%d+)'
|
local read_bytes = 0
|
||||||
|
local write_bytes = 0
|
||||||
local read_stat_file = function()
|
for _, path in pairs(DEVICE_PATHS) do
|
||||||
local bytes_r, bytes_w = __string_match(Util.read_file(STAT_FILE), RW_REGEX)
|
local r, w = __string_match(Util.read_file(path), RW_REGEX)
|
||||||
return __tonumber(bytes_r) * BLOCK_SIZE_BYTES, __tonumber(bytes_w) * BLOCK_SIZE_BYTES
|
read_bytes = read_bytes + __tonumber(r)
|
||||||
|
write_bytes = write_bytes + __tonumber(w)
|
||||||
|
end
|
||||||
|
return read_bytes * BLOCK_SIZE_BYTES, write_bytes * BLOCK_SIZE_BYTES
|
||||||
end
|
end
|
||||||
|
|
||||||
reads.byte_cnt = 0
|
reads.byte_cnt = 0
|
||||||
writes.byte_cnt = 0
|
writes.byte_cnt = 0
|
||||||
reads.prev_byte_cnt, writes.prev_byte_cnt = read_stat_file()
|
reads.prev_byte_cnt, writes.prev_byte_cnt = read_devices()
|
||||||
|
|
||||||
local update_stat = function(cr, stat, byte_cnt)
|
local update_stat = function(cr, stat, byte_cnt)
|
||||||
local delta_bytes = byte_cnt - stat.prev_byte_cnt
|
local delta_bytes = byte_cnt - stat.prev_byte_cnt
|
||||||
|
@ -90,7 +102,7 @@ return function(update_freq)
|
||||||
end
|
end
|
||||||
|
|
||||||
local update = function(cr)
|
local update = function(cr)
|
||||||
local read_byte_cnt, write_byte_cnt = read_stat_file()
|
local read_byte_cnt, write_byte_cnt = read_devices()
|
||||||
update_stat(cr, reads, read_byte_cnt)
|
update_stat(cr, reads, read_byte_cnt)
|
||||||
update_stat(cr, writes, write_byte_cnt)
|
update_stat(cr, writes, write_byte_cnt)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue