dio: return separated read and write statistics

This changes keys that are returned, previously only total I/O was
available in: {raw}, {kb} and {mb}. Keys returned now are (s=raw):
{total_s}, {total_kb}, {total_mb}, {read_s}, {read_kb}, {read_mb},
{write_s},{write_kb} and {write_mb}.
This commit is contained in:
Adrian C. (anrxc) 2009-12-15 00:25:58 +01:00
parent 2c900fa4ee
commit b4031d229d
2 changed files with 26 additions and 18 deletions

23
README
View File

@ -44,7 +44,7 @@ vicious.register() to register it with vicious:
- string argument or a function - string argument or a function
- $1, $2, $3... will be replaced by their respective value - $1, $2, $3... will be replaced by their respective value
returned by the widget type, some widget types return tables returned by the widget type, some widget types return tables
with custom keys, in that case use: ${key} with string keys, in that case use: ${key}
- function - function
- function(widget, args) can be used to manipulate data - function(widget, args) can be used to manipulate data
returned by the widget type, more about this below returned by the widget type, more about this below
@ -137,7 +137,7 @@ vicious.widgets.cpu
vicious.widgets.cpuinf vicious.widgets.cpuinf
- provides speed and cache information for all available CPUs/cores - provides speed and cache information for all available CPUs/cores
- returns a table with custom keys, using CPU ID as a base: - returns a table with string keys, using CPU ID as a base:
{cpu0 mhz}, {cpu0 ghz}, {cpu0 kb}, {cpu0 mb}, {cpu1 mhz} etc. {cpu0 mhz}, {cpu0 ghz}, {cpu0 kb}, {cpu0 mb}, {cpu1 mhz} etc.
vicious.widgets.cpufreq vicious.widgets.cpufreq
@ -176,25 +176,26 @@ vicious.widgets.fs
- provides file system disk space usage - provides file system disk space usage
- takes an (optional) argument which, if true, includes remote file - takes an (optional) argument which, if true, includes remote file
systems, only local file systems are included by default systems, only local file systems are included by default
- returns a table with custom keys, using mount points as a base: - returns a table with string keys, using mount points as a base:
{/ size_mb}, {/ size_gb}, {/ used_mb}, {/ used_gb}, {/ used_p}, {/ size_mb}, {/ size_gb}, {/ used_mb}, {/ used_gb}, {/ used_p},
{/ avail_mb}, {/ avail_gb}, {/home size_mb} etc. {/ avail_mb}, {/ avail_gb}, {/home size_mb} etc.
vicious.widgets.dio vicious.widgets.dio
- provides I/O statistics for requested storage devices - provides I/O statistics for requested storage devices
- takes the disk as an argument, i.e. "hda" - takes the disk as an argument, i.e. "sda"
- returns a table with custom keys: {raw}, {kb} and {mb} - returns a table with string keys: {total_s}, {total_kb}, {total_mb},
{read_s}, {read_kb}, {read_mb}, {write_s},{write_kb} and {write_mb}
vicious.widgets.hddtemp vicious.widgets.hddtemp
- provides hard drive temperatures using the hddtemp daemon - provides hard drive temperatures using the hddtemp daemon
- takes the hddtemp listening port as an argument, or defaults to - takes the hddtemp listening port as an argument, or defaults to
port 7634 port 7634
- returns a table with custom keys, using hard drives as a base: - returns a table with string keys, using hard drives as a base:
{/dev/hda} and {/dev/sda} for example {/dev/sda} and {/dev/sdc} for example
vicious.widgets.net vicious.widgets.net
- provides usage statistics for all network interfaces - provides usage statistics for all network interfaces
- returns a table with custom keys, using net interfaces as a base: - returns a table with string keys, using net interfaces as a base:
{eth0 rx_b}, {eth0 tx_b}, {eth0 rx_kb}, {eth0 tx_kb}, {eth0 rx_mb}, {eth0 rx_b}, {eth0 tx_b}, {eth0 rx_kb}, {eth0 tx_kb}, {eth0 rx_mb},
{eth0 tx_mb}, {eth0 rx_gb}, {eth0 tx_gb}, {eth0 down_b}, {eth0 up_b}, {eth0 tx_mb}, {eth0 rx_gb}, {eth0 tx_gb}, {eth0 down_b}, {eth0 up_b},
{eth0 down_kb}, {eth0 up_kb}, {eth0 down_mb}, {eth0 up_mb}, {eth0 down_kb}, {eth0 up_kb}, {eth0 down_mb}, {eth0 up_mb},
@ -203,7 +204,7 @@ vicious.widgets.net
vicious.widgets.wifi vicious.widgets.wifi
- provides wireless information for a requested interface - provides wireless information for a requested interface
- takes the network interface as an argument, i.e. "wlan0" - takes the network interface as an argument, i.e. "wlan0"
- returns a table with custom keys: {ssid}, {mode}, {chan}, {rate}, - returns a table with string keys: {ssid}, {mode}, {chan}, {rate},
{link} and {sign} {link} and {sign}
vicious.widgets.mbox vicious.widgets.mbox
@ -231,7 +232,7 @@ vicious.widgets.gmail
- takes an (optional) argument, if it's a number subject will be - takes an (optional) argument, if it's a number subject will be
truncated, if a table, with 1st field as maximum lenght and 2nd truncated, if a table, with 1st field as maximum lenght and 2nd
the widget name (i.e. "gmailwidget"), scrolling will be used the widget name (i.e. "gmailwidget"), scrolling will be used
- returns a table with custom keys: {count} and {subject} - returns a table with string keys: {count} and {subject}
vicious.widgets.entropy vicious.widgets.entropy
- provides available system entropy - provides available system entropy
@ -265,7 +266,7 @@ vicious.widgets.volume
vicious.widgets.weather vicious.widgets.weather
- provides weather information for a requested station - provides weather information for a requested station
- takes the ICAO station code as an argument, i.e. "LDRI" - takes the ICAO station code as an argument, i.e. "LDRI"
- returns a table with custom keys: {city}, {wind}, {windmph}, - returns a table with string keys: {city}, {wind}, {windmph},
{windkmh}, {sky}, {weather}, {tempf}, {tempc}, {humid}, {press} {windkmh}, {sky}, {weather}, {tempf}, {tempc}, {humid}, {press}
vicious.widgets.date vicious.widgets.date

21
dio.lua
View File

@ -24,6 +24,15 @@ module("vicious.dio")
local disk_usage = {} local disk_usage = {}
local disk_total = {} local disk_total = {}
-- {{{ Helper functions
local function uformat(array, key, value)
array["{"..key.."_s}"] = string.format("%.1f", value)
array["{"..key.."_kb}"] = string.format("%.1f", value/2)
array["{"..key.."_mb}"] = string.format("%.1f", value/2/1024)
return array
end
-- }}}
-- {{{ Disk I/O widget type -- {{{ Disk I/O widget type
local function worker(format, disk) local function worker(format, disk)
local disk_lines = {} local disk_lines = {}
@ -37,12 +46,11 @@ local function worker(format, disk)
end end
-- Ensure tables are initialized correctly -- Ensure tables are initialized correctly
local diff_total = {}
while #disk_total < #disk_lines do while #disk_total < #disk_lines do
table.insert(disk_total, 0) table.insert(disk_total, 0)
end end
local diff_total = {}
for i, v in ipairs(disk_lines) do for i, v in ipairs(disk_lines) do
-- Diskstats are absolute, substract our last reading -- Diskstats are absolute, substract our last reading
diff_total[i] = v - disk_total[i] diff_total[i] = v - disk_total[i]
@ -51,11 +59,10 @@ local function worker(format, disk)
disk_total[i] = v disk_total[i] = v
end end
-- Calculate I/O -- Calculate and store I/O
disk_usage["{raw}"] = diff_total[7] + diff_total[3] uformat(disk_usage, "read", diff_total[3])
-- Divide "sectors read" by 2 and 1024 to get KB and MB uformat(disk_usage, "write", diff_total[7])
disk_usage["{kb}"] = string.format("%.1f", math.floor(diff_total[7] + diff_total[3])/2) uformat(disk_usage, "total", diff_total[7] + diff_total[3])
disk_usage["{mb}"] = string.format("%.1f", math.floor(diff_total[7] + diff_total[3])/1024)
return disk_usage return disk_usage
end end