Is there a way to get information about memory used in /overlay partition (where system files are stored) as a variable?
I want to run a scene when my memory will be filled above certain limit. I can see that information via “OScommand” section in Alt UI (df - h), but can make a variable which reads and stores such data?
In AltUI I can see amount of memory and percentage of space filled. In my case it can be any of these parameters, as I can refer to the percentage limit or to kB’s used (or left).
local function df()
local format = "(%S+)%s+(%d+)%s+(%d+)%s+(%d+)[^/]+(/%S+)"
local d = {}
local p = io.popen "df"
if p then
local df = p:read "*a"
p: close()
local n = tonumber
for f,b,u,a,m in df: gmatch(format) do
d[#d+1] = {file=f, blocks=n(b), used=n(u), available=n(a), mounted=m}
end
end
return d
end
and calling it on one of my Vera’s gives a structure line this
{
{
available = 0,
blocks = 4608,
file = "/dev/root",
mounted = "/rom",
used = 4608
},{
available = 24904,
blocks = 31240,
file = "tmpfs",
mounted = "/tmp",
used = 6336
},{
available = 512,
blocks = 512,
file = "tmpfs",
mounted = "/dev",
used = 0
},{
available = 7384,
blocks = 11264,
file = "/dev/mtdblock7",
mounted = "/overlay",
used = 3880
},{
available = 0,
blocks = 4480,
file = "/dev/mtdblock8",
mounted = "/mios",
used = 4480
}
}
Thanks for the code, but how can I extract some of the results (lets say I want to have “used” value of "file = “/dev/mtdblock7” parameter)?
Is it possible?
Sorry for asking for direct result, but here my “lua programming” skills are definitely too small.
local function df()
local format = "(%S+)%s+(%d+)%s+(%d+)%s+(%d+)[^/]+(/%S+)"
local d = {}
local p = io.popen "df"
if p then
local df = p:read "*a"
p: close()
local n = tonumber
for f,b,u,a,m in df: gmatch(format) do
d[#d+1] = {file=f, blocks=n(b), used=n(u), available=n(a), mounted=m}
end
end
return d
end
local dfinfo = {}
for _, d in ipairs(df()) do dfinfo[d.file] = d end
local x = dfinfo ["/dev/mtdblock7"]
And then I can use variables as x.available or x.used, in a way like:
if (tonumber(x.available) < [desired limit of memory]) then....
?
Yes, it is definitely over my knowledge, I just don’t want to run clearing code or reboot controller every day, and looking for some smarter solution.
Edit: I’ve tested it, it works!
Thanks for your help!
I modified your code and set to run as part of my daily routine.
local function getOverlayDiskSpace()
local function df()
local format = “(%S+)%s+(%d+)%s+(%d+)%s+(%d+)[^/]+(/%S+)”
local d = {}
local p = io.popen “df”
if p then
local df = p:read “*a”
p: close()
local n = tonumber
for f,b,u,a,m in df: gmatch(format) do
d[#d+1] = {file=f, blocks=n(b), used=n(u), available=n(a), mounted=m}
end
end
return d
end
local dfinfo = {}
for _, d in ipairs(df()) do dfinfo[d.mounted] = d end
local x = dfinfo ["/overlay"]
return (x.available / (x.available + x.used) * 100)
end
local d = getOverlayDiskSpace()
if (d<30) then – alert at 30%
sendAlert("Vera’s Overlay partition at " … tostring(round(d, 2)) … “%”)
end
It will alert you if the partitions is under 30% (we know it’s safe at 20% or more). I just changed to check for the /overlay mounted partition, since mine is mounted as /dev/mtdblock6 instead of /dev/mtdblock6, so I guess it may depend on your system, and I’m using a percentage value, since we know it’s what matters the most.
sendAlert function is my custom function sending alert to my Telegram bot.
I hope I’d be useful to anyone.
Best Home Automation shopping experience. Shop at Ezlo!