system_info_controller.rb 1.13 KB
Newer Older
1
class Admin::SystemInfoController < Admin::ApplicationController
2
3
4
5
  EXCLUDED_MOUNT_OPTIONS = [
    'nobrowse',
    'read-only',
    'ro'
Douwe Maan's avatar
Douwe Maan committed
6
  ].freeze
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

  EXCLUDED_MOUNT_TYPES = [
    'autofs',
    'binfmt_misc',
    'cgroup',
    'debugfs',
    'devfs',
    'devpts',
    'devtmpfs',
    'efivarfs',
    'fuse.gvfsd-fuse',
    'fuseblk',
    'fusectl',
    'hugetlbfs',
    'mqueue',
    'proc',
    'pstore',
24
    'rpc_pipefs',
25
26
27
28
29
    'securityfs',
    'sysfs',
    'tmpfs',
    'tracefs',
    'vfat'
Douwe Maan's avatar
Douwe Maan committed
30
  ].freeze
31

32
  def show
Sean McGivern's avatar
Sean McGivern committed
33
34
    @cpus = Vmstat.cpu rescue nil
    @memory = Vmstat.memory rescue nil
35
36
37
38
    mounts = Sys::Filesystem.mounts

    @disks = []
    mounts.each do |mount|
39
      mount_options = mount.options.split(',')
40

41
42
      next if (EXCLUDED_MOUNT_OPTIONS & mount_options).any?
      next if (EXCLUDED_MOUNT_TYPES & [mount.mount_type]).any?
43

44
45
46
      begin
        disk = Sys::Filesystem.stat(mount.mount_point)
        @disks.push({
47
48
49
50
          bytes_total: disk.bytes_total,
          bytes_used:  disk.bytes_used,
          disk_name:   mount.name,
          mount_path:  disk.path
51
52
53
        })
      rescue Sys::Filesystem::Error
      end
54
    end
55
56
  end
end