Skip to content

Commit

Permalink
add disk usage system function for widget
Browse files Browse the repository at this point in the history
  • Loading branch information
TanvirOnGH committed Jul 6, 2024
1 parent 1f1be35 commit dc5d72f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,23 @@ function system.cpu_usage(storage)
return { total = total_usage, core = core_usage, diff = diff_time_total }
end

-- Get disk usage info
function system.disk_usage(args)
args = args or "/"
local disk_info = {}

-- Get disk info
local line = modutil.read.output("LC_ALL=C df -kP " .. args .. " | tail -1")

-- Parse data
disk_info.size = string.match(line, "^.-[%s]([%d]+)")
disk_info.mount = string.match(line, "%%[%s]([%p%w]+)")
disk_info.used, disk_info.avail, disk_info.use_p = string.match(line, "([%d]+)[%D]+([%d]+)[%D]+([%d]+)%%")

-- Format output special for flex desktop widget
return { tonumber(disk_info.use_p) or 0, tonumber(disk_info.used) or 0 }
end

-- Temperature measure
-- Using lm-sensors
system.lmsensors = { storage = {}, patterns = {}, delay = 1, time = 0 }
Expand Down Expand Up @@ -609,4 +626,18 @@ function system.pformatted.swap(crit)
end
end

-- DISK usage formatted special for panel widget
function system.pformatted.disk(crit)
crit = crit or 85

return function()
local disk_info = system.disk_usage()
return {
value = disk_info[1] / 100,
text = "DISK: " .. disk_info[1] .. "%",
alert = disk_info[1] > crit,
}
end
end

return system

0 comments on commit dc5d72f

Please sign in to comment.