Add file systems
This commit is contained in:
1 parent
a282debfbd
commit
1e87b08b54
3 files changed
+100
-4
No files matched your search
@@ -63,6 +63,41 @@ def read_smart(name)
|
||||
result
|
||||
end
|
||||
|
||||
def read_filesystems
|
||||
out = `findmnt -J -b -o SOURCE,TARGET,FSTYPE,SIZE,USED 2>/dev/null`
|
||||
return [] if out.empty?
|
||||
data = JSON.parse(out) rescue nil
|
||||
return [] unless data
|
||||
|
||||
skip_fstypes = %w[tmpfs devtmpfs efivarfs]
|
||||
result = []
|
||||
seen = {}
|
||||
stack = Array(data["filesystems"]).dup
|
||||
until stack.empty?
|
||||
node = stack.shift
|
||||
stack.concat(node["children"]) if node["children"]
|
||||
source = node["source"].to_s
|
||||
fstype = node["fstype"].to_s
|
||||
target = node["target"].to_s
|
||||
next unless source.start_with?("/dev/")
|
||||
next if skip_fstypes.include?(fstype)
|
||||
size = node["size"].to_i
|
||||
next if size <= 0
|
||||
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
|
||||
}
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def handle_info(conn)
|
||||
info = []
|
||||
|
||||
@@ -89,6 +124,8 @@ def handle_info(conn)
|
||||
info << entry
|
||||
end
|
||||
|
||||
info.concat(read_filesystems)
|
||||
|
||||
if conn
|
||||
conn.puts JSON.generate(info)
|
||||
else
|
||||
|
||||
Reference in new issue
Block a user