Class: OsCtl::Lib::Zfs::IOStat
- Inherits:
-
Object
- Object
- OsCtl::Lib::Zfs::IOStat
- Defined in:
- lib/libosctl/zfs/iostat.rb
Defined Under Namespace
Classes: PoolStats
Instance Attribute Summary collapse
-
#accumulated_stats ⇒ Object
readonly
protected
Returns the value of attribute accumulated_stats.
-
#current_stats ⇒ Object
readonly
protected
Returns the value of attribute current_stats.
- #interval ⇒ Integer readonly
-
#iostat_pid ⇒ Object
readonly
protected
Returns the value of attribute iostat_pid.
-
#mutex ⇒ Object
readonly
protected
Returns the value of attribute mutex.
- #pools ⇒ Array<String>
-
#reader ⇒ Object
readonly
protected
Returns the value of attribute reader.
Instance Method Summary collapse
- #accumulated_all ⇒ PoolStats
- #accumulated_pool(pool) ⇒ PoolStats
- #add_pool(pool) ⇒ Object
- #current_all ⇒ PoolStats
- #current_pool(pool) ⇒ PoolStats
-
#initialize(pools: nil, interval: 1) ⇒ IOStat
constructor
A new instance of IOStat.
- #parser(r) ⇒ Object protected
- #remove_pool(pool) ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
- #stop ⇒ Object
- #sync ⇒ Object protected
Constructor Details
#initialize(pools: nil, interval: 1) ⇒ IOStat
Returns a new instance of IOStat.
30 31 32 33 34 35 36 37 38 |
# File 'lib/libosctl/zfs/iostat.rb', line 30 def initialize(pools: nil, interval: 1) @pools = pools @interval = interval @current_stats = {} @accumulated_stats = {} @current_all = nil @accumulated_all = PoolStats.new(nil, nil, nil, 0, 0, 0, 0) @mutex = Mutex.new end |
Instance Attribute Details
#accumulated_stats ⇒ Object (readonly, protected)
Returns the value of attribute accumulated_stats.
141 142 143 |
# File 'lib/libosctl/zfs/iostat.rb', line 141 def accumulated_stats @accumulated_stats end |
#current_stats ⇒ Object (readonly, protected)
Returns the value of attribute current_stats.
141 142 143 |
# File 'lib/libosctl/zfs/iostat.rb', line 141 def current_stats @current_stats end |
#interval ⇒ Integer (readonly)
26 27 28 |
# File 'lib/libosctl/zfs/iostat.rb', line 26 def interval @interval end |
#iostat_pid ⇒ Object (readonly, protected)
Returns the value of attribute iostat_pid.
141 142 143 |
# File 'lib/libosctl/zfs/iostat.rb', line 141 def iostat_pid @iostat_pid end |
#mutex ⇒ Object (readonly, protected)
Returns the value of attribute mutex.
141 142 143 |
# File 'lib/libosctl/zfs/iostat.rb', line 141 def mutex @mutex end |
#pools ⇒ Array<String>
23 24 25 |
# File 'lib/libosctl/zfs/iostat.rb', line 23 def pools @pools end |
#reader ⇒ Object (readonly, protected)
Returns the value of attribute reader.
141 142 143 |
# File 'lib/libosctl/zfs/iostat.rb', line 141 def reader @reader end |
Instance Method Details
#accumulated_all ⇒ PoolStats
135 136 137 |
# File 'lib/libosctl/zfs/iostat.rb', line 135 def accumulated_all sync { @accumulated_all } end |
#accumulated_pool(pool) ⇒ PoolStats
125 126 127 |
# File 'lib/libosctl/zfs/iostat.rb', line 125 def accumulated_pool(pool) sync { accumulated_stats[pool] } end |
#add_pool(pool) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/libosctl/zfs/iostat.rb', line 71 def add_pool(pool) @pools ||= [] return if pools.include?(pool) pools << pool stop if started? start nil end |
#current_all ⇒ PoolStats
130 131 132 |
# File 'lib/libosctl/zfs/iostat.rb', line 130 def current_all sync { @current_all } end |
#current_pool(pool) ⇒ PoolStats
119 120 121 |
# File 'lib/libosctl/zfs/iostat.rb', line 119 def current_pool(pool) sync { current_stats[pool] } end |
#parser(r) ⇒ Object (protected)
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/libosctl/zfs/iostat.rb', line 144 def parser(r) r.each_line do |line| pool, alloc, free, rio, wio, rbytes, wbytes = line.strip.split("\t") st = PoolStats.new( pool, alloc.to_i, free.to_i, rio.to_i, wio.to_i, rbytes.to_i, wbytes.to_i ) sync do current_stats[pool] = st if accumulated_stats.has_key?(pool) accumulated_stats[pool] << st else accumulated_stats[pool] = st end @current_all = st @accumulated_all << st end end rescue IOError # ignore end |
#remove_pool(pool) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/libosctl/zfs/iostat.rb', line 82 def remove_pool(pool) return if pools.nil? || !pools.include?(pool) pools.delete(pool) return unless started? stop sync do current_stats.delete(pool) accumulated_stats.delete(pool) end start nil end |
#start ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/libosctl/zfs/iostat.rb', line 40 def start return if pools.is_a?(Array) && pools.empty? args = ['zpool', 'iostat', '-Hpy'] args.concat(pools) if pools args << interval.to_s r, w = IO.pipe @reader = Thread.new { parser(r) } @iostat_pid = Process.spawn(*args, out: w) w.close end |
#started? ⇒ Boolean
53 54 55 |
# File 'lib/libosctl/zfs/iostat.rb', line 53 def started? !reader.nil? end |
#stop ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/libosctl/zfs/iostat.rb', line 57 def stop if iostat_pid Process.kill('TERM', iostat_pid) Process.wait(iostat_pid) @iostat_pid = nil end return unless reader reader.join @reader = nil end |
#sync ⇒ Object (protected)
174 175 176 |
# File 'lib/libosctl/zfs/iostat.rb', line 174 def sync(&) mutex.synchronize(&) end |