| 1 |
|
| 2 |
|
| 3 |
> |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
local tonumber = tonumber |
| 22 |
local io = { popen = io.popen } |
| 23 |
local setmetatable = setmetatable |
| 24 |
local table = { insert = table.insert } |
| 25 |
local string = { |
| 26 |
gsub = string.gsub, |
| 27 |
match = string.match |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
local sensors_linux = {} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
local function datasplit(str) |
| 39 |
|
| 40 |
|
| 41 |
str = string.gsub(str, "\n", ":") |
| 42 |
|
| 43 |
local tbl = {} |
| 44 |
string.gsub(str, "([^:]*)", function (v) |
| 45 |
if string.match(v, ".") then |
| 46 |
table.insert(tbl, v) |
| 47 |
end |
| 48 |
end) |
| 49 |
|
| 50 |
local assoc = {} |
| 51 |
for c = 1, #tbl, 2 do |
| 52 |
local k = string.gsub(tbl[c], ".*_", "") |
| 53 |
local v = tonumber(string.match(tbl[c+1], "[%d]+")) |
| 54 |
assoc[k] = v |
| 55 |
end |
| 56 |
|
| 57 |
return assoc |
| 58 |
end |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
local function worker(format, warg) |
| 63 |
|
| 64 |
local f = io.popen("LANG=C sensors -uA") |
| 65 |
local lm_sensors = f:read("*all") |
| 66 |
f:close() |
| 67 |
|
| 68 |
local sensor_data = string.gsub( |
| 69 |
string.match(lm_sensors, warg..":\n(%s%s.-)\n[^ ]"), " ", "") |
| 70 |
|
| 71 |
|
| 72 |
local divisor = "crit" |
| 73 |
local s_data = datasplit(sensor_data) |
| 74 |
|
| 75 |
if s_data[divisor] and s_data[divisor] > 0 then |
| 76 |
s_data.percent = s_data.input / s_data[divisor] * 100 |
| 77 |
end |
| 78 |
|
| 79 |
return {s_data.input, tonumber(s_data.percent)} |
| 80 |
end |
| 81 |
|
| 82 |
|
| 83 |
return setmetatable(sensors_linux, { __call = function(_, ...) return worker(...) end }) |