Read sysctl Key (sys.ctlbyname)
Declaration
data = sys.ctlbyname(key)
Parameters
- key
String. Full sysctl key name, for examplekern.boottimeorhw.memsize.
Returns
- data
String. Raw byte data returned by the key. Returnsnilwhen the key cannot be read.
Description
Calls the underlying sysctlbyname to fetch kernel or hardware runtime parameters.
Use this to retrieve sysctl values, inspect kernel state, or capture metrics. The raw data often needs additional unpacking.
Examples
local raw = sys.ctlbyname('hw.machine')
if type(raw) == 'string' then
nLog('Device type: '..raw:gsub('%z+$', ''))
else
nLog('Failed to read hw.machine')
end
local sec, usec = string.unpack('li', sys.ctlbyname('kern.boottime'))
nLog('Seconds since boot', os.time() - sec)