Class: OsCtl::Cli::Top::Host
Defined Under Namespace
Classes: Cpu
Instance Attribute Summary collapse
Attributes inherited from Container
#cpu_package_inuse, #dataset, #group_path, #id, #ident, #init_pid, #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
#initialize(iostat_reader) ⇒ Host
Returns a new instance of Host.
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/osctl/cli/top/host.rb', line 60
def initialize(iostat_reader)
super(id: '[host]', pool: nil, group_path: '', state: 'running')
@iostat_reader = iostat_reader
@pools = []
@cpu = []
@zfs = []
@objsets = nil
@netifs = :all
@netif_stats = OsCtl::Lib::NetifStats.new
end
|
Instance Attribute Details
#iostat_reader ⇒ Object
Returns the value of attribute iostat_reader.
108
109
110
|
# File 'lib/osctl/cli/top/host.rb', line 108
def iostat_reader
@iostat_reader
end
|
#netif_stats ⇒ Object
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
Returns the value of attribute objsets.
57
58
59
|
# File 'lib/osctl/cli/top/host.rb', line 57
def objsets
@objsets
end
|
#pools ⇒ Object
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
75
76
77
|
# File 'lib/osctl/cli/top/host.rb', line 75
def container?
false
end
|
#cpu_result ⇒ Object
98
99
100
|
# File 'lib/osctl/cli/top/host.rb', line 98
def cpu_result
@cpu[1].diff(@cpu[0])
end
|
#diff_arcstats(current, previous) ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/osctl/cli/top/host.rb', line 143
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
134
135
136
137
138
139
|
# File 'lib/osctl/cli/top/host.rb', line 134
def diff_zfs(current, previous)
{
arcstats: diff_arcstats(current[:arcstats], previous[:arcstats]),
iostat: current[:iostat] && get_iostat(current[:iostat])
}
end
|
#get_iostat(current) ⇒ Object
161
162
163
164
165
166
167
168
|
# File 'lib/osctl/cli/top/host.rb', line 161
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
79
80
81
82
83
84
85
|
# File 'lib/osctl/cli/top/host.rb', line 79
def measure(subsystems)
netif_stats.reset
measure_objsets
super(self, subsystems)
measure_host_cpu_hz
measure_zfs
end
|
#measure_host_cpu_hz ⇒ Object
110
111
112
113
114
115
116
117
118
|
# File 'lib/osctl/cli/top/host.rb', line 110
def measure_host_cpu_hz
f = File.open('/proc/stat')
str = f.readline
f.close
values = str.strip.split
@cpu << Cpu.new(* values[1..].map(&:to_i))
@cpu.shift if @cpu.size > 2
end
|
#measure_objsets ⇒ Object
128
129
130
|
# File 'lib/osctl/cli/top/host.rb', line 128
def measure_objsets
@objsets = OsCtl::Lib::Zfs::ObjsetStats.read_pools(pools)
end
|
#measure_zfs ⇒ Object
120
121
122
123
124
125
126
|
# File 'lib/osctl/cli/top/host.rb', line 120
def measure_zfs
@zfs << {
arcstats: Top::ArcStats.new,
iostat: iostat_reader && iostat_reader.current_all
}
@zfs.shift if @zfs.size > 2
end
|
#result(mode, meminfo, lavg) ⇒ Object
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/osctl/cli/top/host.rb', line 87
def result(mode, meminfo, lavg)
ret = super(mode)
ret[:memory] = meminfo.used * 1024
ret[:nproc] = lavg.total
ret
end
|
#running? ⇒ Boolean
71
72
73
|
# File 'lib/osctl/cli/top/host.rb', line 71
def running?
true
end
|
#zfs_result ⇒ Object
102
103
104
|
# File 'lib/osctl/cli/top/host.rb', line 102
def zfs_result
diff_zfs(@zfs[1], @zfs[0])
end
|