2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
|
|
|
-- * (c) 2009, Adrian C. <anrxc.sysphere.org>
|
|
|
|
-- * (c) Wicked, Lucas de Vries
|
|
|
|
---------------------------------------------------
|
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
|
|
|
|
local tonumber = tonumber
|
|
|
|
local os = { time = os.time }
|
|
|
|
local io = { open = io.open }
|
2009-08-01 23:11:41 +02:00
|
|
|
local setmetatable = setmetatable
|
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 math = { floor = math.floor }
|
2009-10-05 00:10:47 +02:00
|
|
|
local string = { match = string.match }
|
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
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- Net: provides usage statistics for all network interfaces
|
|
|
|
module("vicious.net")
|
|
|
|
|
|
|
|
|
|
|
|
-- Initialise function tables
|
|
|
|
local nets = {}
|
|
|
|
|
|
|
|
-- {{{ Net widget type
|
2009-08-07 17:41:10 +02:00
|
|
|
local function worker(format)
|
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
|
|
|
-- Get /proc/net/dev
|
|
|
|
local f = io.open("/proc/net/dev")
|
|
|
|
local args = {}
|
|
|
|
|
|
|
|
for line in f:lines() do
|
|
|
|
-- Match wmaster0 as well as rt0 (multiple leading spaces)
|
2009-10-05 00:10:47 +02:00
|
|
|
if string.match(line, "^[%s]?[%s]?[%s]?[%s]?[%w]+:") then
|
|
|
|
local name = string.match(line, "^[%s]?[%s]?[%s]?[%s]?([%w]+):")
|
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
|
|
|
-- Received bytes, first value after the name
|
2009-10-05 00:10:47 +02:00
|
|
|
local recv = tonumber(string.match(line, ":[%s]*([%d]+)"))
|
|
|
|
local send = -- Transmited bytes, 7 fields from end of the line
|
|
|
|
tonumber(string.match(line, "([%d]+)%s+%d+%s+%d+%s+%d+%s+%d+%s+%d+%s+%d+%s+%d$"))
|
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
|
|
|
|
|
|
|
args["{"..name.." rx_b}"] = math.floor(recv*10)/10
|
|
|
|
args["{"..name.." tx_b}"] = math.floor(send*10)/10
|
|
|
|
|
|
|
|
args["{"..name.." rx_kb}"] = math.floor(recv/1024*10)/10
|
|
|
|
args["{"..name.." tx_kb}"] = math.floor(send/1024*10)/10
|
|
|
|
|
|
|
|
args["{"..name.." rx_mb}"] = math.floor(recv/1024/1024*10)/10
|
|
|
|
args["{"..name.." tx_mb}"] = math.floor(send/1024/1024*10)/10
|
|
|
|
|
|
|
|
args["{"..name.." rx_gb}"] = math.floor(recv/1024/1024/1024*10)/10
|
|
|
|
args["{"..name.." tx_gb}"] = math.floor(send/1024/1024/1024*10)/10
|
|
|
|
|
|
|
|
if nets[name] == nil then
|
2009-09-14 17:25:23 +02:00
|
|
|
-- Default values on the first run
|
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
|
|
|
nets[name] = {}
|
2009-10-10 00:24:23 +02:00
|
|
|
args["{"..name.." down}"] = "N/A"
|
|
|
|
args["{"..name.." up}"] = "N/A"
|
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
|
|
|
|
|
|
|
args["{"..name.." down_b}"] = 0
|
|
|
|
args["{"..name.." up_b}"] = 0
|
|
|
|
|
|
|
|
args["{"..name.." down_kb}"] = 0
|
|
|
|
args["{"..name.." up_kb}"] = 0
|
|
|
|
|
|
|
|
args["{"..name.." down_mb}"] = 0
|
|
|
|
args["{"..name.." up_mb}"] = 0
|
|
|
|
|
|
|
|
args["{"..name.." down_gb}"] = 0
|
|
|
|
args["{"..name.." up_gb}"] = 0
|
|
|
|
|
|
|
|
nets[name].time = os.time()
|
|
|
|
else
|
|
|
|
-- Net stats are absolute, substract our last reading
|
2009-10-04 00:21:15 +02:00
|
|
|
local interval = os.time() - nets[name].time
|
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
|
|
|
nets[name].time = os.time()
|
|
|
|
|
2009-10-04 00:21:15 +02:00
|
|
|
local down = (recv - nets[name][1])/interval
|
|
|
|
local up = (send - nets[name][2])/interval
|
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
|
|
|
|
|
|
|
args["{"..name.." down_b}"] = math.floor(down*10)/10
|
|
|
|
args["{"..name.." up_b}"] = math.floor(up*10)/10
|
|
|
|
|
|
|
|
args["{"..name.." down_kb}"] = math.floor(down/1024*10)/10
|
|
|
|
args["{"..name.." up_kb}"] = math.floor(up/1024*10)/10
|
|
|
|
|
|
|
|
args["{"..name.." down_mb}"] = math.floor(down/1024/1024*10)/10
|
|
|
|
args["{"..name.." up_mb}"] = math.floor(up/1024/1024*10)/10
|
|
|
|
|
|
|
|
args["{"..name.." down_gb}"] = math.floor(down/1024/1024/1024*10)/10
|
|
|
|
args["{"..name.." up_gb}"] = math.floor(up/1024/1024/1024*10)/10
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Store totals
|
|
|
|
nets[name][1] = recv
|
|
|
|
nets[name][2] = send
|
|
|
|
end
|
|
|
|
end
|
|
|
|
f:close()
|
|
|
|
|
|
|
|
return args
|
|
|
|
end
|
|
|
|
-- }}}
|
2009-08-01 23:11:41 +02:00
|
|
|
|
|
|
|
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
|