Merge branch 'improve-system-info' into 'master'

Catch permission denied errors and ignore the disk



See merge request !5017
This commit is contained in:
Stan Hu 2016-07-01 02:05:22 +00:00
commit ab81ea1e81

View file

@ -1,20 +1,45 @@
class Admin::SystemInfoController < Admin::ApplicationController
def show
excluded_mounts = [
"nobrowse",
"read-only",
"ro"
EXCLUDED_MOUNT_OPTIONS = [
'nobrowse',
'read-only',
'ro'
]
EXCLUDED_MOUNT_TYPES = [
'autofs',
'binfmt_misc',
'cgroup',
'debugfs',
'devfs',
'devpts',
'devtmpfs',
'efivarfs',
'fuse.gvfsd-fuse',
'fuseblk',
'fusectl',
'hugetlbfs',
'mqueue',
'proc',
'pstore',
'securityfs',
'sysfs',
'tmpfs',
'tracefs',
'vfat'
]
def show
system_info = Vmstat.snapshot
mounts = Sys::Filesystem.mounts
@disks = []
mounts.each do |mount|
options = mount.options.split(', ')
mount_options = mount.options.split(',')
next unless excluded_mounts.each { |em| break if options.include?(em) }
next if (EXCLUDED_MOUNT_OPTIONS & mount_options).any?
next if (EXCLUDED_MOUNT_TYPES & [mount.mount_type]).any?
begin
disk = Sys::Filesystem.stat(mount.mount_point)
@disks.push({
bytes_total: disk.bytes_total,
@ -22,6 +47,8 @@ class Admin::SystemInfoController < Admin::ApplicationController
disk_name: mount.name,
mount_path: disk.path
})
rescue Sys::Filesystem::Error
end
end
@cpus = system_info.cpus.length