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

Attributes inherited from Container

#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



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

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

Instance Method Details

#container?Boolean

Returns:

  • (Boolean)


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

def container?
  false
end

#cpu_resultObject



86
87
88
# File 'lib/osctl/cli/top/host.rb', line 86

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

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

Parameters:



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/osctl/cli/top/host.rb', line 112

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



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

def measure(subsystems)
  super
  measure_host_cpu_hz
  measure_zfs
end

#measure_host_cpu_hzObject (protected)



95
96
97
98
99
100
101
102
103
# File 'lib/osctl/cli/top/host.rb', line 95

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_zfsObject (protected)



105
106
107
108
# File 'lib/osctl/cli/top/host.rb', line 105

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

#result(mode, meminfo) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/osctl/cli/top/host.rb', line 74

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)


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

def running?
  true
end

#zfs_resultObject



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

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