Class: OsCtl::Cli::Top::Container
- Inherits:
-
Object
- Object
- OsCtl::Cli::Top::Container
- Defined in:
- lib/osctl/cli/top/container.rb
Defined Under Namespace
Classes: NetIf
Instance Attribute Summary collapse
-
#cpu_package_inuse ⇒ Object
Returns the value of attribute cpu_package_inuse.
-
#dataset ⇒ Object
readonly
Returns the value of attribute dataset.
-
#group_path ⇒ Object
readonly
Returns the value of attribute group_path.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#ident ⇒ Object
readonly
Returns the value of attribute ident.
-
#init_pid ⇒ Object
Returns the value of attribute init_pid.
-
#init_start_time_ticks ⇒ Object
Returns the value of attribute init_start_time_ticks.
-
#initial ⇒ Object
readonly
protected
Returns the value of attribute initial.
-
#measurements ⇒ Object
readonly
protected
Returns the value of attribute measurements.
-
#netifs ⇒ Object
Returns the value of attribute netifs.
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #[](k) ⇒ Object
- #container? ⇒ Boolean
- #core_delta_error ⇒ Object
- #current_measurement ⇒ Object
- #find_netif(name) ⇒ Object protected
- #has_netif?(name) ⇒ Boolean
-
#initialize(ct = nil, enable_netif: true, enable_zfs: true, **attrs) ⇒ Container
constructor
A new instance of Container.
- #measure(host, subsystems) ⇒ Object
- #netif_down(name) ⇒ Object
- #netif_rename(name, new_name) ⇒ Object
- #netif_rm(name) ⇒ Object
- #netif_up(name, veth) ⇒ Object
- #reset_measurements(keep_current: false) ⇒ Object
- #result(mode) ⇒ Object
- #running? ⇒ Boolean
- #setup? ⇒ Boolean
- #snapshot ⇒ Object
- #update(ct) ⇒ Object
Constructor Details
#initialize(ct = nil, enable_netif: true, enable_zfs: true, **attrs) ⇒ Container
Returns a new instance of Container.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/osctl/cli/top/container.rb', line 14 def initialize(ct = nil, enable_netif: true, enable_zfs: true, **attrs) ct ||= attrs @enable_netif = enable_netif @enable_zfs = enable_zfs @id = ct[:id] @pool = ct[:pool] @ident = "#{@pool}:#{@id}" @dataset = ct[:dataset] @group_path = ct[:group_path] @state = ct[:state].to_sym @cpu_package_inuse = ct[:cpu_package_inuse] @init_pid = ct[:init_pid] @netifs = [] @measurements = [] @initial = nil end |
Instance Attribute Details
#cpu_package_inuse ⇒ Object
Returns the value of attribute cpu_package_inuse.
11 12 13 |
# File 'lib/osctl/cli/top/container.rb', line 11 def cpu_package_inuse @cpu_package_inuse end |
#dataset ⇒ Object (readonly)
Returns the value of attribute dataset.
10 11 12 |
# File 'lib/osctl/cli/top/container.rb', line 10 def dataset @dataset end |
#group_path ⇒ Object (readonly)
Returns the value of attribute group_path.
10 11 12 |
# File 'lib/osctl/cli/top/container.rb', line 10 def group_path @group_path end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/osctl/cli/top/container.rb', line 10 def id @id end |
#ident ⇒ Object (readonly)
Returns the value of attribute ident.
10 11 12 |
# File 'lib/osctl/cli/top/container.rb', line 10 def ident @ident end |
#init_pid ⇒ Object
Returns the value of attribute init_pid.
11 12 13 |
# File 'lib/osctl/cli/top/container.rb', line 11 def init_pid @init_pid end |
#init_start_time_ticks ⇒ Object
Returns the value of attribute init_start_time_ticks.
11 12 13 |
# File 'lib/osctl/cli/top/container.rb', line 11 def init_start_time_ticks @init_start_time_ticks end |
#initial ⇒ Object (readonly, protected)
Returns the value of attribute initial.
133 134 135 |
# File 'lib/osctl/cli/top/container.rb', line 133 def initial @initial end |
#measurements ⇒ Object (readonly, protected)
Returns the value of attribute measurements.
133 134 135 |
# File 'lib/osctl/cli/top/container.rb', line 133 def measurements @measurements end |
#netifs ⇒ Object
Returns the value of attribute netifs.
11 12 13 |
# File 'lib/osctl/cli/top/container.rb', line 11 def netifs @netifs end |
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
10 11 12 |
# File 'lib/osctl/cli/top/container.rb', line 10 def pool @pool end |
#state ⇒ Object
Returns the value of attribute state.
11 12 13 |
# File 'lib/osctl/cli/top/container.rb', line 11 def state @state end |
Instance Method Details
#[](k) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/osctl/cli/top/container.rb', line 31 def [](k) # Used by OsCtl::Lib::LoadAvgReader case k when :id @id when :pool @pool when :init_pid @init_pid else raise ArgumentError, "key #{k.inspect} is not supported" end end |
#container? ⇒ Boolean
53 54 55 |
# File 'lib/osctl/cli/top/container.rb', line 53 def container? true end |
#core_delta_error ⇒ Object
91 92 93 94 95 |
# File 'lib/osctl/cli/top/container.rb', line 91 def core_delta_error return 'initial_baseline' unless setup? current_measurement.delta_error(measurements[-2]) end |
#current_measurement ⇒ Object
87 88 89 |
# File 'lib/osctl/cli/top/container.rb', line 87 def current_measurement measurements.last end |
#find_netif(name) ⇒ Object (protected)
135 136 137 |
# File 'lib/osctl/cli/top/container.rb', line 135 def find_netif(name) netifs.detect { |netif| netif.name == name } end |
#has_netif?(name) ⇒ Boolean
127 128 129 |
# File 'lib/osctl/cli/top/container.rb', line 127 def has_netif?(name) !find_netif(name).nil? end |
#measure(host, subsystems) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/osctl/cli/top/container.rb', line 57 def measure(host, subsystems) m = Top::Measurement.new(host, subsystems, group_path, dataset, netifs, enable_netif: @enable_netif, enable_zfs: @enable_zfs) m.measure @initial = m if measurements.empty? measurements << m measurements.shift if measurements.size > 2 end |
#netif_down(name) ⇒ Object
112 113 114 115 |
# File 'lib/osctl/cli/top/container.rb', line 112 def netif_down(name) netif = find_netif(name) netif.veth = nil end |
#netif_rename(name, new_name) ⇒ Object
122 123 124 125 |
# File 'lib/osctl/cli/top/container.rb', line 122 def netif_rename(name, new_name) netif = find_netif(name) netif.name = new_name end |
#netif_rm(name) ⇒ Object
117 118 119 120 |
# File 'lib/osctl/cli/top/container.rb', line 117 def netif_rm(name) netif = find_netif(name) netifs.delete(netif) end |
#netif_up(name, veth) ⇒ Object
107 108 109 110 |
# File 'lib/osctl/cli/top/container.rb', line 107 def netif_up(name, veth) netif = find_netif(name) netif.veth = veth end |
#reset_measurements(keep_current: false) ⇒ Object
82 83 84 85 |
# File 'lib/osctl/cli/top/container.rb', line 82 def reset_measurements(keep_current: false) @measurements = keep_current && !measurements.empty? ? [measurements.last] : [] @initial = @measurements.first end |
#result(mode) ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/osctl/cli/top/container.rb', line 97 def result(mode) case mode when :realtime measurements[1].diff_from(measurements[0], mode) when :cumulative measurements[1].diff_from(initial, mode) end end |
#running? ⇒ Boolean
49 50 51 |
# File 'lib/osctl/cli/top/container.rb', line 49 def running? @state == :running end |
#setup? ⇒ Boolean
45 46 47 |
# File 'lib/osctl/cli/top/container.rb', line 45 def setup? measurements.count >= 2 end |
#snapshot ⇒ Object
66 67 68 69 70 71 |
# File 'lib/osctl/cli/top/container.rb', line 66 def snapshot copy = dup copy.instance_variable_set(:@measurements, measurements.dup) copy.netifs = netifs == :all ? :all : netifs.map(&:dup) copy end |
#update(ct) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/osctl/cli/top/container.rb', line 73 def update(ct) reset_measurements if group_path != ct[:group_path] || init_pid != ct[:init_pid] || state != ct[:state].to_sym @dataset = ct[:dataset] @group_path = ct[:group_path] @state = ct[:state].to_sym @init_pid = ct[:init_pid] @cpu_package_inuse = ct[:cpu_package_inuse] end |