Show file system inode usage and read-only status

This commit is contained in:
josh committed 2026-04-14 08:41:39 -04:00
1 parent 1e87b08b54
commit 23008b4997
2 files changed
+51 -13

No files matched your search

+25 -8
View File
@@ -3,6 +3,7 @@
require "socket"
require "fileutils"
require "json"
require "shellwords"
SOCKET_PATH = "/run/malpd/malpd.sock"
@@ -63,8 +64,16 @@ def read_smart(name)
result
end
def read_inodes(mount)
out = `stat -f -c '%c %d' #{Shellwords.escape(mount)} 2>/dev/null`.strip
return nil if out.empty?
total, free = out.split.map(&:to_i)
return nil unless total && total > 0
[total, total - free]
end
def read_filesystems
out = `findmnt -J -b -o SOURCE,TARGET,FSTYPE,SIZE,USED 2>/dev/null`
out = `findmnt -J -b -o SOURCE,TARGET,FSTYPE,SIZE,USED,OPTIONS 2>/dev/null`
return [] if out.empty?
data = JSON.parse(out) rescue nil
return [] unless data
@@ -86,14 +95,22 @@ def read_filesystems
key = [source, target]
next if seen[key]
seen[key] = true
result << {
"type" => "filesystem",
"source" => source,
"mount" => target,
"fstype" => fstype,
"size" => size,
"used" => node["used"].to_i
opts = node["options"].to_s.split(",")
entry = {
"type" => "filesystem",
"source" => source,
"mount" => target,
"fstype" => fstype,
"size" => size,
"used" => node["used"].to_i,
"readonly" => opts.include?("ro")
}
if (ino = read_inodes(target))
entry["inode_total"] = ino[0]
entry["inode_used"] = ino[1]
end
result << entry
end
result
end