2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
2011-03-21 21:04:57 +01:00
|
|
|
-- * (c) 2011, Jörg T. <jthalheim@gmail.com>
|
2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
|
|
|
|
-- {{{ Grab environment
|
2011-03-21 21:04:57 +01:00
|
|
|
local pairs = pairs
|
2011-03-29 02:21:53 +02:00
|
|
|
local io = { lines = io.lines }
|
2009-08-01 23:11:41 +02:00
|
|
|
local setmetatable = setmetatable
|
2011-03-29 16:41:24 +02:00
|
|
|
local string = { match = string.match }
|
2009-11-11 03:00:33 +01:00
|
|
|
local helpers = require("vicious.helpers")
|
2011-03-29 02:21:53 +02:00
|
|
|
local os = {
|
|
|
|
time = os.time,
|
|
|
|
difftime = os.difftime
|
|
|
|
}
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
2011-03-21 21:04:57 +01:00
|
|
|
-- Disk I/O: provides I/O statistics for storage devices/partitions (only linux >= 2.6 )
|
2010-03-14 01:55:33 +01:00
|
|
|
module("vicious.widgets.dio")
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
|
|
|
|
|
2010-04-02 01:08:12 +02:00
|
|
|
-- Initialize function tables
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
local disk_usage = {}
|
2011-03-29 02:21:53 +02:00
|
|
|
local disk_stats = {}
|
|
|
|
local disk_time = 0
|
2011-03-21 21:04:57 +01:00
|
|
|
-- Constant definitions
|
2010-02-20 03:24:42 +01:00
|
|
|
local unit = { ["s"] = 1, ["kb"] = 2, ["mb"] = 2048 }
|
2010-03-12 03:44:42 +01:00
|
|
|
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
-- {{{ Disk I/O widget type
|
2011-03-21 21:04:57 +01:00
|
|
|
local function worker(format)
|
2011-03-29 02:21:53 +02:00
|
|
|
local disk_lines = {}
|
|
|
|
|
|
|
|
for line in io.lines("/proc/diskstats") do
|
|
|
|
local device, read, write =
|
2011-03-29 16:41:24 +02:00
|
|
|
-- Linux kernel documentation: Documentation/iostats.txt
|
|
|
|
string.match(line, "([^%s]+) %d+ %d+ (%d+) %d+ %d+ %d+ (%d+)")
|
2011-03-29 02:21:53 +02:00
|
|
|
disk_lines[device] = { read, write }
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
end
|
|
|
|
|
2011-03-29 02:21:53 +02:00
|
|
|
local time = os.time()
|
|
|
|
local interval = os.difftime(time, disk_time)
|
|
|
|
if interval == 0 then interval = 1 end
|
2011-03-21 21:04:57 +01:00
|
|
|
|
2011-03-29 02:21:53 +02:00
|
|
|
for device, stats in pairs(disk_lines) do
|
|
|
|
-- Avoid insane values on startup
|
|
|
|
local last_stats = disk_stats[device] or stats
|
2011-03-21 21:04:57 +01:00
|
|
|
|
2011-03-29 02:21:53 +02:00
|
|
|
-- Check for overflows and counter resets (> 2^32)
|
|
|
|
if stats[1] < last_stats[1] or stats[2] < last_stats[2] then
|
|
|
|
last_stats[1], last_stats[2] = stats[1], stats[2]
|
2009-12-15 02:38:20 +01:00
|
|
|
end
|
2011-03-21 21:04:57 +01:00
|
|
|
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
-- Diskstats are absolute, substract our last reading
|
2011-03-29 02:21:53 +02:00
|
|
|
-- * divide by timediff because we don't know the timer value
|
|
|
|
local read = (stats[1] - last_stats[1]) / interval
|
|
|
|
local write = (stats[2] - last_stats[2]) / interval
|
2011-03-21 21:04:57 +01:00
|
|
|
|
2011-03-29 02:21:53 +02:00
|
|
|
-- Calculate and store I/O
|
|
|
|
helpers.uformat(disk_usage, device.." read", read, unit)
|
|
|
|
helpers.uformat(disk_usage, device.." write", write, unit)
|
|
|
|
helpers.uformat(disk_usage, device.." total", read + write, unit)
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
end
|
2011-03-21 21:04:57 +01:00
|
|
|
|
2011-03-29 02:21:53 +02:00
|
|
|
disk_time = time
|
|
|
|
disk_stats = disk_lines
|
2011-03-21 21:04:57 +01:00
|
|
|
|
2011-03-29 02:21:53 +02:00
|
|
|
return disk_usage
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
end
|
|
|
|
-- }}}
|
2009-08-01 23:11:41 +02:00
|
|
|
|
|
|
|
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
|