small improvements for freebsd

This commit is contained in:
mutlusun 2017-01-21 13:05:06 +01:00
parent 1f8793077b
commit 0a3af4168d
6 changed files with 155 additions and 88 deletions

View File

@ -141,20 +141,18 @@ string.
**vicious.widgets.bat**
Provides state, charge, and remaining time for a requested battery.
Supported platforms: Linux, FreeBSD.
Supported platforms: Linux (required tools: `sysfs`), FreeBSD (required tools:
`acpiconf`).
- Arguments (per platform):
* Linux: takes battery ID as an argument, i.e. "BAT0"
* FreeBSD: takes optional battery ID as an argument, i.e. "batt"
* Linux: takes battery ID as an argument, i.e. `"BAT0"`
* FreeBSD: takes optional battery ID as an argument, i.e. `"batt"` or `"0"`
- Returns (per platform):
* Linux: returns 1st value as state of requested battery, 2nd as charge
level in percent, 3rd as remaining (charging or discharging) time and 4th
as the wear level in percent
* FreeBSD: see Linux, but there's is 5th value for the present dis-/charge
rate in mW.
- Requirements (per platform):
* Linux: sysfs
* FreeBSD: "acpiconf", but can be called as user
**vicious.widgets.cpu**
@ -173,8 +171,8 @@ Provides freq, voltage and governor info for a requested CPU.
Supported platforms: Linux, FreeBSD.
- Arguments (per platform):
* Linux: takes the CPU ID as an argument, i.e. "cpu0"
* FreeBSD: takes the CPU ID as an argument, i.e. "0"
* Linux: takes the CPU ID as an argument, i.e. `"cpu0"`
* FreeBSD: takes the CPU ID as an argument, i.e. `"0"`
- Returns (per platform):
* Linux: returns 1st value as frequency of requested CPU in MHz, 2nd in GHz,
3rd as voltage in mV, 4th as voltage in V and 5th as the governor state
@ -220,13 +218,12 @@ Supported platforms: Linux.
**vicious.widget.fanspeed**
Provides fanspeed information for specified fan.
Supported platforms: FreeBSD
Supported platforms: FreeBSD.
- Arguments:
* FreeBSD: full sysctl string to entry, i.e. "dev.acpi_ibm.0.fan_speed"
-Returns:
* FreeBSD: speed of specified fan as number,
-1 for error (probably wrong string)
* Full sysctl string to entry, i.e. `"dev.acpi_ibm.0.fan_speed"`
- Returns:
* Speed of specified fan as number, `-1` for error (probably wrong string)
**vicious.widgets.fs**
@ -307,6 +304,22 @@ Supported platforms: platform independent.
* returns 1st value as the count of new messages and 2nd as the count of
"old" messages lacking the Seen flag
**vicious.widgets.mem**
Provides RAM and Swap usage statistics.
Supported platforms: Linux, FreeBSD.
- Arguments:
* None
- Returns (per platform):
* Linux: returns 1st value as memory usage in percent, 2nd as memory usage, 3rd as
total system memory, 4th as free memory, 5th as swap usage in percent, 6th
as swap usage, 7th as total system swap, 8th as free swap and 9th as
memory usage with buffers and cache
* FreeBSD: see above, but 10th value as memory usage with buffers and cache
as percent and 11th value as wired memory (memory used by kernel) is
reported
**vicious.widgets.mpd**
Provides Music Player Daemon information.
@ -385,9 +398,9 @@ Provides state information for a requested RAID array.
Supported platforms: Linux.
- Arguments:
* takes the RAID array ID as an argument
* Takes the RAID array ID as an argument
- Returns:
* returns 1st value as the number of assigned, and 2nd as active, devices in
* Returns 1st value as the number of assigned, and 2nd as active, devices in
the array
**vicious.widgets.thermal**
@ -401,9 +414,11 @@ Supported platforms: Linux, FreeBSD.
sources are "proc", "core" and "sys" (which is the default when only the
zone is provided) and 3rd optional argument as a temperature input file to
read
* FreeBSD: takes the thermal zone as an argument, i.e. `"0"`
* FreeBSD: takes the full sysctl path to a thermal zone as an argument, i.e.
`"hw.acpi.thermal.tz0.temperature"`, or a table with multiple paths
- Returns:
* returns 1st value as temperature of requested thermal zone
* Linux: returns 1st value as temperature of requested thermal zone
* FreeBSD: returns a table with a entry for every input thermal zone
**vicious.widgets.uptime**
@ -413,7 +428,7 @@ Supported platforms: Linux, FreeBSD.
- Arguments:
* None
- Returns:
* returns 1st value as uptime in days, 2nd as uptime in hours, 3rd as uptime
* Returns 1st value as uptime in days, 2nd as uptime in hours, 3rd as uptime
in minutes, 4th as load average for past 1 minute, 5th for 5 minutes and
6th for 15 minutes
@ -439,20 +454,12 @@ Provides weather information for a requested station.
Supported platforms: platform independent (required tools: `curl`).
- Arguments:
* takes the ICAO station code as an argument, i.e. "LDRI"
* Takes the ICAO station code as an argument, i.e. "LDRI"
- Returns:
* returns a table with string keys: `{city}`, `{wind}`, `{windmph}`,
* Returns a table with string keys: `{city}`, `{wind}`, `{windmph}`,
`{windkmh}`, `{sky}`, `{weather}`, `{tempf}`, `{tempc}`, `{humid}`,
`{dewf}`, `{dewc}` and `{press}`
**vicious.widgets.mem**
- provides RAM and Swap usage statistics
- returns 1st value as memory usage in percent, 2nd as memory usage,
3rd as total system memory, 4th as free memory, 5th as swap usage
in percent, 6th as swap usage, 7th as total system swap, 8th as
free swap and 9th as memory usage with buffers and cache
**vicious.widgets.wifi**
- provides wireless information for a requested interface

View File

@ -1,19 +1,21 @@
-----------------------------------------------------
-- Battery: use acpiconf to get more information
-- from the battery
-----------------------------------------------------
-- {{{ Grab environment
local setmetatable = setmetatable
-- }}}
local bat_acpi = {}
local tonumber = tonumber
local io = { popen = io.popen }
local math = { floor = math.floor }
local string = {
gmatch = string.gmatch,
gsub = string.gsub,
format = string.format
local function worker(format)
local battery = "batt"
if warg then
battery = warg
end
}
-- }}}
local bat_freebsd = {}
local function worker(format, warg)
local battery = warg or "batt"
local bat_info = {}
local pcall = "acpiconf -i " .. battery
local f = io.popen(pcall)
local f = io.popen("acpiconf -i " .. battery)
for line in f:lines("*line") do
for key,value in string.gmatch(line, "(.+):%s+(.+)") do
bat_info[key] = value
@ -47,12 +49,12 @@ local function worker(format)
if bat_info["Last full capacity"] and bat_info["Design capacity"] then
local l_full = tonumber(string.gsub(bat_info["Last full capacity"], "[^%d]", ""), 10)
local design = tonumber(string.gsub(bat_info["Design capacity"], "[^%d]", ""), 10)
wear = math.floor( 100 - (l_full / design * 100))
wear = math.floor(100 - (l_full / design * 100))
end
-- dis-/charging rate as presented by battery
local rate = string.gsub( string.gsub(bat_info["Present rate"], ".*mA[^%d]+", ""), "[%s]+mW.*", "")
rate = string.format( "% 2.1f", tonumber(rate / 1000))
local rate = string.gsub(string.gsub(bat_info["Present rate"], ".*mA[^%d]+", ""), "[%s]+mW.*", "")
rate = string.format("%2.1f", tonumber(rate / 1000))
-- returns
-- * state (high "↯", discharging "-", charging "+", N/A "⌁" }
@ -63,4 +65,4 @@ local function worker(format)
return {state, percent, time, wear, rate}
end
return setmetatable(bat_acpi, { __call = function(_, ...) return worker(...) end })
return setmetatable(bat_freebsd, { __call = function(_, ...) return worker(...) end })

View File

@ -1,20 +1,21 @@
--
-- {{{ Grab environment
local setmetatable = setmetatable
local helpers = require("vicious.helpers")
local tonumber = tonumber
-- }}}
-- fanspeed: provides speed level of main fan
--
-- expects one (1) full sysctl string to entry
-- e.g.: "dev.acpi_ibm.0.fan_speed"
-- environment
local setmetatable = setmetatable
local string = { match = string.match }
local helpers = require("vicious.helpers")
local fanspeed_freebsd = {}
local function worker(format, warg)
if not warg then return end
local fanspeed = helpers.sysctl( "" .. warg .. "" )
local fanspeed = helpers.sysctl(warg)
if not fanspeed then
-- use negative fanspeed to indicate error

View File

@ -1,27 +1,27 @@
----------------------------------------------
-- Mem: provides RAM and Swap usage statistics
----------------------------------------------
-- Grab environment --
-- {{{ Grab environment
local tonumber = tonumber
local setmetatable = setmetatable
local math = { floor = math.floor }
local helpers = require("vicious.helpers")
-- }}}
-- Mem: provides RAM and Swap usage statistics
-- vicious.widgets.mem_freebsd
local mem_freebsd = {}
-- Memory widget type --
-- {{{ Memory widget type
local function worker(format)
local hw = helpers.sysctl_table("hw")
local pagesize = tonumber(helpers.sysctl("hw.pagesize"))
local vm_stats = helpers.sysctl_table("vm.stats.vm")
local _mem = { buf = {}, total = nil }
_mem.total = tonumber(vm_stats.v_page_count) * tonumber(hw.pagesize)
_mem.buf.f = tonumber(vm_stats.v_free_count) * tonumber(hw.pagesize)
_mem.buf.a = tonumber(vm_stats.v_active_count) * tonumber(hw.pagesize)
_mem.buf.i = tonumber(vm_stats.v_inactive_count) * tonumber(hw.pagesize)
_mem.buf.c = tonumber(vm_stats.v_cache_count) * tonumber(hw.pagesize)
_mem.buf.w = tonumber(vm_stats.v_wire_count) * tonumber(hw.pagesize)
_mem.total = tonumber(vm_stats.v_page_count) * pagesize
_mem.buf.f = tonumber(vm_stats.v_free_count) * pagesize
_mem.buf.a = tonumber(vm_stats.v_active_count) * pagesize
_mem.buf.i = tonumber(vm_stats.v_inactive_count) * pagesize
_mem.buf.c = tonumber(vm_stats.v_cache_count) * pagesize
_mem.buf.w = tonumber(vm_stats.v_wire_count) * pagesize
-- rework into Megabytes
_mem.total = math.floor(_mem.total/(1024*1024))
@ -41,26 +41,29 @@ local function worker(format)
_mem.buffp = math.floor(_mem.bcuse / _mem.total * 100)
_mem.wirep = math.floor(_mem.wire / _mem.total * 100)
-- @todo: expand to get swap states
-- local vm = helpers.sysctl_table("vm")
-- local _swp = { buf = {}, total = nil }
-- if vm.swap_enable == 1 and vm.swap_total > 0 then
-- _swp_.usep =
-- _swp.total = tonumber(vm.swap_total) * tonumber(hw.pagesize)
-- _swp_inuse =
-- _swp_free =
-- end
-- use default values until i get some swap
-- Get swap states
local vm = helpers.sysctl_table("vm")
local _swp = { buf = {}, total = nil }
_swp_usep = -1
_swp.inuse = -1
_swp.free = -1
_swp.total = -1
if tonumber(vm.swap_enabled) == 1 and tonumber(vm.swap_total) > 0 then
-- Get swap space
_swp.total = tonumber(vm.swap_total)
_swp.buf.f = _swp.total - tonumber(vm_stats.v_swapin)
-- Rework into megabytes
_swp.total = math.floor(_swp.total/(1024*1024))
_swp.buf.f = math.floor(_swp.buf.f/(1024*1024))
-- Calculate percentage
_swp.inuse = _swp.total - _swp.buf.f
_swp.usep = math.floor(_swp.inuse / _swp.total * 100)
else
_swp.usep = -1
_swp.inuse = -1
_swp.total = -1
_swp.buf.f = -1
end
return { _mem.usep, _mem.inuse, _mem.total, _mem.free,
_swp.usep, _swp.inuse, _swp.total, _swp.free,
_swp.usep, _swp.inuse, _swp.total, _swp.buf.f,
_mem.bcuse, _mem.buffp, _mem.wirep }
end

52
widgets/mem_linux.lua Normal file
View File

@ -0,0 +1,52 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
-- * (c) 2009, Lucas de Vries <lucas@glacicle.com>
---------------------------------------------------
-- {{{ Grab environment
local io = { lines = io.lines }
local setmetatable = setmetatable
local math = { floor = math.floor }
local string = { gmatch = string.gmatch }
-- }}}
-- Mem: provides RAM and Swap usage statistics
-- vicious.widgets.mem
local mem = {}
-- {{{ Memory widget type
local function worker(format)
local _mem = { buf = {}, swp = {} }
-- Get MEM info
for line in io.lines("/proc/meminfo") do
for k, v in string.gmatch(line, "([%a]+):[%s]+([%d]+).+") do
if k == "MemTotal" then _mem.total = math.floor(v/1024)
elseif k == "MemFree" then _mem.buf.f = math.floor(v/1024)
elseif k == "Buffers" then _mem.buf.b = math.floor(v/1024)
elseif k == "Cached" then _mem.buf.c = math.floor(v/1024)
elseif k == "SwapTotal" then _mem.swp.t = math.floor(v/1024)
elseif k == "SwapFree" then _mem.swp.f = math.floor(v/1024)
end
end
end
-- Calculate memory percentage
_mem.free = _mem.buf.f + _mem.buf.b + _mem.buf.c
_mem.inuse = _mem.total - _mem.free
_mem.bcuse = _mem.total - _mem.buf.f
_mem.usep = math.floor(_mem.inuse / _mem.total * 100)
-- Calculate swap percentage
_mem.swp.inuse = _mem.swp.t - _mem.swp.f
_mem.swp.usep = math.floor(_mem.swp.inuse / _mem.swp.t * 100)
return {_mem.usep, _mem.inuse, _mem.total, _mem.free,
_mem.swp.usep, _mem.swp.inuse, _mem.swp.t, _mem.swp.f,
_mem.bcuse }
end
-- }}}
return setmetatable(mem, { __call = function(_, ...) return worker(...) end })

View File

@ -2,6 +2,7 @@
local setmetatable = setmetatable
local string = { match = string.match }
local helpers = require("vicious.helpers")
local tonumber = tonumber
-- }}}
@ -13,18 +14,19 @@ local thermal_freebsd = {}
-- {{{ Thermal widget type
local function worker(format, warg)
if not warg then return end
local thermals = {}
local cnt = 1
while cnt <= #warg do
local output = helpers.sysctl( "" .. warg[cnt] .. "" )
for i=1, #warg do
local output = helpers.sysctl(warg[i])
if not output then
thermals[cnt] = 0
thermals[i] = -1
else
thermals[cnt] = tonumber( string.match(output, "[%d][%d]") )
thermals[i] = string.match(output, "[%d]+")
end
cnt = cnt + 1
end
return thermals
end
-- }}}