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.
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/osctl/cli/top/host.rb', line 58
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.
105
106
107
|
# File 'lib/osctl/cli/top/host.rb', line 105
def iostat_reader
@iostat_reader
end
|
#netif_stats ⇒ Object
Returns the value of attribute netif_stats.
55
56
57
|
# File 'lib/osctl/cli/top/host.rb', line 55
def netif_stats
@netif_stats
end
|
#objsets ⇒ Object
Returns the value of attribute objsets.
55
56
57
|
# File 'lib/osctl/cli/top/host.rb', line 55
def objsets
@objsets
end
|
#pools ⇒ Object
Returns the value of attribute pools.
55
56
57
|
# File 'lib/osctl/cli/top/host.rb', line 55
def pools
@pools
end
|
Instance Method Details
#container? ⇒ Boolean
73
74
75
|
# File 'lib/osctl/cli/top/host.rb', line 73
def container?
false
end
|
#cpu_result ⇒ Object
96
97
98
|
# File 'lib/osctl/cli/top/host.rb', line 96
def cpu_result
@cpu[1].diff(@cpu[0])
end
|
#diff_arcstats(current, previous) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/osctl/cli/top/host.rb', line 140
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
131
132
133
134
135
136
|
# File 'lib/osctl/cli/top/host.rb', line 131
def diff_zfs(current, previous)
{
arcstats: diff_arcstats(current[:arcstats], previous[:arcstats]),
iostat: current[:iostat] && get_iostat(current[:iostat]),
}
end
|
#get_iostat(current) ⇒ Object
158
159
160
161
162
163
164
165
|
# File 'lib/osctl/cli/top/host.rb', line 158
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
77
78
79
80
81
82
83
|
# File 'lib/osctl/cli/top/host.rb', line 77
def measure(subsystems)
netif_stats.reset
measure_objsets
super(self, subsystems)
measure_host_cpu_hz
measure_zfs
end
|
#measure_host_cpu_hz ⇒ Object
107
108
109
110
111
112
113
114
115
|
# File 'lib/osctl/cli/top/host.rb', line 107
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_objsets ⇒ Object
125
126
127
|
# File 'lib/osctl/cli/top/host.rb', line 125
def measure_objsets
@objsets = OsCtl::Lib::Zfs::ObjsetStats.read_pools(pools)
end
|
#measure_zfs ⇒ Object
117
118
119
120
121
122
123
|
# File 'lib/osctl/cli/top/host.rb', line 117
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
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/osctl/cli/top/host.rb', line 85
def result(mode, meminfo, lavg)
ret = super(mode)
ret[:memory] = meminfo.used * 1024
ret[:nproc] = lavg.total
ret
end
|
#running? ⇒ Boolean
69
70
71
|
# File 'lib/osctl/cli/top/host.rb', line 69
def running?
true
end
|
#zfs_result ⇒ Object
100
101
102
|
# File 'lib/osctl/cli/top/host.rb', line 100
def zfs_result
diff_zfs(@zfs[1], @zfs[0])
end
|