Class: OsCtl::Cli::Top::Host

Inherits:
Container show all
Defined in:
lib/osctl/cli/top/host.rb

Defined Under Namespace

Classes: Cpu

Instance Attribute Summary collapse

Attributes inherited from Container

#dataset, #group_path, #id, #initial, #measurements, #netifs, #pool, #state

Instance Method Summary collapse

Methods inherited from Container

#find_netif, #has_netif?, #netif_down, #netif_rename, #netif_rm, #netif_up, #setup?

Constructor Details

#initializeHost

Returns a new instance of Host.



56
57
58
59
60
61
62
# File 'lib/osctl/cli/top/host.rb', line 56

def initialize
  super(id: '[host]', pool: nil, group_path: '', state: 'running')
  @pools = []
  @cpu = []
  @zfs = []
  @objsets = nil
end

Instance Attribute Details

#objsetsObject (readonly)

Returns the value of attribute objsets.



54
55
56
# File 'lib/osctl/cli/top/host.rb', line 54

def objsets
  @objsets
end

#poolsObject (readonly)

Returns the value of attribute pools.



54
55
56
# File 'lib/osctl/cli/top/host.rb', line 54

def pools
  @pools
end

Instance Method Details

#container?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/osctl/cli/top/host.rb', line 68

def container?
  false
end

#cpu_resultObject



91
92
93
# File 'lib/osctl/cli/top/host.rb', line 91

def cpu_result
  @cpu[1].diff(@cpu[0])
end

#diff_zfs(current, previous) ⇒ Object (protected)

Parameters:



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/osctl/cli/top/host.rb', line 121

def diff_zfs(current, previous)
  {
    arc: {
      c_max: current.c_max,
      c: current.c,
      size: current.size,
      hit_rate: current.hit_rate(previous),
      misses: current.misses(previous),
    },
    l2arc: {
      size: current.l2_size,
      asize: current.l2_asize,
      hit_rate: current.l2_hit_rate(previous),
      misses: current.l2_misses(previous),
    },
  }
end

#measure(subsystems) ⇒ Object



72
73
74
75
76
77
# File 'lib/osctl/cli/top/host.rb', line 72

def measure(subsystems)
  measure_objsets
  super(self, subsystems)
  measure_host_cpu_hz
  measure_zfs
end

#measure_host_cpu_hzObject (protected)



100
101
102
103
104
105
106
107
108
# File 'lib/osctl/cli/top/host.rb', line 100

def measure_host_cpu_hz
  f = File.open('/proc/stat')
  str = f.readline
  f.close

  values = str.strip.split
  @cpu << Cpu.new(* values[1..-1].map(&:to_i))
  @cpu.shift if @cpu.size > 2
end

#measure_objsetsObject (protected)



115
116
117
# File 'lib/osctl/cli/top/host.rb', line 115

def measure_objsets
  @objsets = OsCtl::Lib::Zfs::ObjsetStats.read_pools(pools)
end

#measure_zfsObject (protected)



110
111
112
113
# File 'lib/osctl/cli/top/host.rb', line 110

def measure_zfs
  @zfs << Top::ArcStats.new
  @zfs.shift if @zfs.size > 2
end

#result(mode, meminfo) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/osctl/cli/top/host.rb', line 79

def result(mode, meminfo)
  ret = super(mode)

  # memory from the root cgroup does not account for all used memory
  ret[:memory] = meminfo.used * 1024

  # root pids cgroup does not have process counter
  ret[:nproc] = `ps axh -opid | wc -l`.strip.to_i

  ret
end

#running?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/osctl/cli/top/host.rb', line 64

def running?
  true
end

#zfs_resultObject



95
96
97
# File 'lib/osctl/cli/top/host.rb', line 95

def zfs_result
  diff_zfs(@zfs[1], @zfs[0])
end