-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgetinfo.lua
49 lines (43 loc) · 1.09 KB
/
getinfo.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
--------------------------------------------------------------------------------
-- @author john
-- @copyright 2011 https://github.com/tuxcodejohn
-- @release v3.4-503-g4972a28
--------------------------------------------------------------------------------
getinfo = {}
local io = require('io')
--- Network Interfaces
-- @return list of all network interfaces (without `lo`)
function getinfo.interfaces()
local f = io.popen("ls /sys/class/net", "r")
local out = assert(f:read("*a"))
f:close()
local ret = {}
for w in string.gmatch(out, "%w+") do
f,emsg,enum = io.open("/sys/class/net/".. w .. "/device" ,"r")
if (enum ~= 2 ) then
table.insert(ret, w)
end
end
return ret
end
--- CPUs
-- @return list of all cpus
function getinfo.local_cpus()
local cpu_lines = {}
local c = ""
local v = ""
for line in io.lines("/proc/stat") do
v= nil
v, c = string.find(line, "^(cpu%d+)")
if v then
table.insert(cpu_lines, string.sub(line,v,c))
end
end
return cpu_lines
end
--- CPU Count
-- @return number of cpus
function getinfo.cpu_count()
return #getinfo.local_cpus()
end
return getinfo