Class: OsCtl::Cli::Top::Host
- Inherits:
-
Top::Container
- Object
- Top::Container
- OsCtl::Cli::Top::Host
- Defined in:
- lib/osctl/cli/top/host.rb
Defined Under Namespace
Classes: Cpu
Instance Attribute Summary collapse
-
#iostat_reader ⇒ Object
readonly
protected
Returns the value of attribute iostat_reader.
-
#netif_stats ⇒ Object
readonly
Returns the value of attribute netif_stats.
-
#objsets ⇒ Object
readonly
Returns the value of attribute objsets.
-
#pools ⇒ Object
readonly
Returns the value of attribute pools.
Instance Method Summary collapse
- #container? ⇒ Boolean
- #core_delta_error ⇒ Object
- #cpu_result ⇒ Object
- #diff_arcstats(current, previous) ⇒ Object protected
- #diff_zfs(current, previous) ⇒ Object protected
- #get_iostat(current) ⇒ Object protected
-
#initialize(iostat_reader, enable_netif: true, enable_zfs: true) ⇒ Host
constructor
A new instance of Host.
- #measure(subsystems) ⇒ Object
- #measure_host_cpu_hz ⇒ Object protected
- #measure_objsets ⇒ Object protected
- #measure_zfs ⇒ Object protected
- #reset_measurements(keep_current: false) ⇒ Object
- #result(mode, meminfo, lavg) ⇒ Object
- #running? ⇒ Boolean
- #snapshot ⇒ Object
- #zfs_result ⇒ Object
Constructor Details
#initialize(iostat_reader, enable_netif: true, enable_zfs: true) ⇒ Host
Returns a new instance of Host.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/osctl/cli/top/host.rb', line 60 def initialize(iostat_reader, enable_netif: true, enable_zfs: true) super({ id: '[host]', pool: nil, group_path: '', state: 'running' }, enable_netif:, enable_zfs:) @iostat_reader = iostat_reader @pools = [] @cpu = [] @zfs = [] @objsets = nil @netifs = :all @netif_stats = enable_netif ? OsCtl::Lib::NetifStats.new : nil end |
Instance Attribute Details
#iostat_reader ⇒ Object (readonly, protected)
Returns the value of attribute iostat_reader.
149 150 151 |
# File 'lib/osctl/cli/top/host.rb', line 149 def iostat_reader @iostat_reader end |
#netif_stats ⇒ Object (readonly)
Returns the value of attribute netif_stats.
57 58 59 |
# File 'lib/osctl/cli/top/host.rb', line 57 def netif_stats @netif_stats end |
#objsets ⇒ Object (readonly)
Returns the value of attribute objsets.
57 58 59 |
# File 'lib/osctl/cli/top/host.rb', line 57 def objsets @objsets end |
#pools ⇒ Object (readonly)
Returns the value of attribute pools.
57 58 59 |
# File 'lib/osctl/cli/top/host.rb', line 57 def pools @pools end |
Instance Method Details
#container? ⇒ Boolean
76 77 78 |
# File 'lib/osctl/cli/top/host.rb', line 76 def container? false end |
#core_delta_error ⇒ Object
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/osctl/cli/top/host.rb', line 136 def core_delta_error return 'initial_baseline' unless @cpu.size == 2 return 'invalid_window' unless @cpu[-1].time > @cpu[-2].time return 'counter_reset' if @cpu[-1].each_pair.any? { |k, v| v < @cpu[-2][k] } total = cpu_result.total return 'invalid_host_cpu_delta' unless total.finite? && total > 0 nil end |
#cpu_result ⇒ Object
112 113 114 |
# File 'lib/osctl/cli/top/host.rb', line 112 def cpu_result @cpu[1].diff(@cpu[0]) end |
#diff_arcstats(current, previous) ⇒ Object (protected)
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/osctl/cli/top/host.rb', line 189 def diff_arcstats(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 |
#diff_zfs(current, previous) ⇒ Object (protected)
180 181 182 183 184 185 |
# File 'lib/osctl/cli/top/host.rb', line 180 def diff_zfs(current, previous) { arcstats: diff_arcstats(current[:arcstats], previous[:arcstats]), iostat: current[:iostat] && get_iostat(current[:iostat]) } end |
#get_iostat(current) ⇒ Object (protected)
207 208 209 210 211 212 213 214 |
# File 'lib/osctl/cli/top/host.rb', line 207 def get_iostat(current) { io_read: current.io_read, io_written: current.io_written, bytes_read: current.bytes_read, bytes_written: current.bytes_written } end |
#measure(subsystems) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/osctl/cli/top/host.rb', line 80 def measure(subsystems) if @enable_netif begin @netif_stats ||= OsCtl::Lib::NetifStats.new netif_stats.reset rescue StandardError @netif_stats = nil end end if @enable_zfs begin measure_objsets rescue StandardError @objsets = nil end end super(self, subsystems) measure_host_cpu_hz measure_zfs if @enable_zfs end |
#measure_host_cpu_hz ⇒ Object (protected)
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/osctl/cli/top/host.rb', line 151 def measure_host_cpu_hz values = File.open('/proc/stat', &:readline).split raise Top::Measurement::Error, 'invalid host CPU' unless values.shift == 'cpu' && values.size >= 10 counters = values.take(10).map { |v| Integer(v, 10) } raise Top::Measurement::Error, 'invalid host CPU' if counters.any?(&:negative?) @cpu << Cpu.new(*counters) @cpu.shift if @cpu.size > 2 end |
#measure_objsets ⇒ Object (protected)
174 175 176 |
# File 'lib/osctl/cli/top/host.rb', line 174 def measure_objsets @objsets = OsCtl::Lib::Zfs::ObjsetStats.read_pools(pools) end |
#measure_zfs ⇒ Object (protected)
162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/osctl/cli/top/host.rb', line 162 def measure_zfs begin @zfs << { arcstats: Top::ArcStats.new, iostat: iostat_reader && iostat_reader.current_all } rescue StandardError @zfs << nil end @zfs.shift if @zfs.size > 2 end |
#reset_measurements(keep_current: false) ⇒ Object
130 131 132 133 134 |
# File 'lib/osctl/cli/top/host.rb', line 130 def reset_measurements(keep_current: false) super @cpu = keep_current && !@cpu.empty? ? [@cpu.last] : [] @zfs = keep_current && !@zfs.empty? ? [@zfs.last] : [] end |
#result(mode, meminfo, lavg) ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/osctl/cli/top/host.rb', line 101 def result(mode, meminfo, lavg) ret = super(mode) # memory from the root cgroup does not account for all used memory ret[:memory] = meminfo.used * 1024 ret[:nproc] = lavg.total ret end |
#running? ⇒ Boolean
72 73 74 |
# File 'lib/osctl/cli/top/host.rb', line 72 def running? true end |
#snapshot ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/osctl/cli/top/host.rb', line 122 def snapshot copy = super copy.instance_variable_set(:@cpu, @cpu.dup) copy.instance_variable_set(:@zfs, @zfs.dup) copy.instance_variable_set(:@pools, @pools.dup) copy end |
#zfs_result ⇒ Object
116 117 118 119 120 |
# File 'lib/osctl/cli/top/host.rb', line 116 def zfs_result return nil unless @enable_zfs && @zfs.size == 2 && @zfs.all? diff_zfs(@zfs[1], @zfs[0]) end |