Add Server Info card
This commit is contained in:
1 parent
5687d8a4e7
commit
49a20a946f
2 files changed
+106
No files matched your search
@@ -166,6 +166,52 @@ def read_virtual_machines
|
||||
end
|
||||
end
|
||||
|
||||
def read_server_info
|
||||
info = { "type" => "server" }
|
||||
|
||||
if File.exist?("/etc/os-release")
|
||||
File.readlines("/etc/os-release").each do |line|
|
||||
if line =~ /^PRETTY_NAME="(.+)"$/
|
||||
info["os_name"] = $1
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
out = `stat -c %W / 2>/dev/null`.strip
|
||||
if out =~ /^\d+$/ && out.to_i > 0
|
||||
info["install_date"] = Time.at(out.to_i).strftime("%Y-%m-%d")
|
||||
elsif File.exist?("/etc/machine-id")
|
||||
info["install_date"] = File.mtime("/etc/machine-id").strftime("%Y-%m-%d")
|
||||
end
|
||||
|
||||
if File.exist?("/proc/cpuinfo")
|
||||
cpuinfo = File.read("/proc/cpuinfo")
|
||||
if cpuinfo =~ /^model name\s*:\s*(.+)$/
|
||||
info["cpu_model"] = $1.strip
|
||||
end
|
||||
cores = cpuinfo.scan(/^processor\s*:/).size
|
||||
info["cpu_cores"] = cores if cores > 0
|
||||
end
|
||||
|
||||
if File.exist?("/proc/meminfo")
|
||||
mem = {}
|
||||
File.read("/proc/meminfo").each_line do |line|
|
||||
if line =~ /^(\w+):\s+(\d+)/
|
||||
mem[$1] = $2.to_i * 1024
|
||||
end
|
||||
end
|
||||
if (total = mem["MemTotal"])
|
||||
available = mem["MemAvailable"] ||
|
||||
(mem["MemFree"].to_i + mem["Buffers"].to_i + mem["Cached"].to_i)
|
||||
info["mem_total"] = total
|
||||
info["mem_used"] = total - available
|
||||
end
|
||||
end
|
||||
|
||||
info
|
||||
end
|
||||
|
||||
def read_ups
|
||||
out = `apcaccess 2>/dev/null`
|
||||
return nil unless $?.success? && !out.empty?
|
||||
@@ -232,6 +278,8 @@ def handle_info(conn)
|
||||
info.concat(read_filesystems)
|
||||
info.concat(read_virtual_machines)
|
||||
|
||||
info << read_server_info
|
||||
|
||||
if (ups = read_ups)
|
||||
info << ups
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user