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.
32 33 34 35 36 37 38 39 40 |
# File 'lib/libosctl/zfs/iostat.rb', line 32 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.
143 144 145 |
# File 'lib/libosctl/zfs/iostat.rb', line 143 def accumulated_stats @accumulated_stats end |
#current_stats ⇒ Object (readonly, protected)
Returns the value of attribute current_stats.
143 144 145 |
# File 'lib/libosctl/zfs/iostat.rb', line 143 def current_stats @current_stats end |
#interval ⇒ Integer (readonly)
28 29 30 |
# File 'lib/libosctl/zfs/iostat.rb', line 28 def interval @interval end |
#iostat_pid ⇒ Object (readonly, protected)
Returns the value of attribute iostat_pid.
143 144 145 |
# File 'lib/libosctl/zfs/iostat.rb', line 143 def iostat_pid @iostat_pid end |
#mutex ⇒ Object (readonly, protected)
Returns the value of attribute mutex.
143 144 145 |
# File 'lib/libosctl/zfs/iostat.rb', line 143 def mutex @mutex end |
#pools ⇒ Array<String>
25 26 27 |
# File 'lib/libosctl/zfs/iostat.rb', line 25 def pools @pools end |
#reader ⇒ Object (readonly, protected)
Returns the value of attribute reader.
143 144 145 |
# File 'lib/libosctl/zfs/iostat.rb', line 143 def reader @reader end |
Instance Method Details
#accumulated_all ⇒ PoolStats
138 139 140 |
# File 'lib/libosctl/zfs/iostat.rb', line 138 def accumulated_all sync { @accumulated_all } end |
#accumulated_pool(pool) ⇒ PoolStats
128 129 130 |
# File 'lib/libosctl/zfs/iostat.rb', line 128 def accumulated_pool(pool) sync { accumulated_stats[pool] } end |
#add_pool(pool) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/libosctl/zfs/iostat.rb', line 73 def add_pool(pool) @pools ||= [] return if pools.include?(pool) pools << pool stop if started? start nil end |
#current_all ⇒ PoolStats
133 134 135 |
# File 'lib/libosctl/zfs/iostat.rb', line 133 def current_all sync { @current_all } end |
#current_pool(pool) ⇒ PoolStats
122 123 124 |
# File 'lib/libosctl/zfs/iostat.rb', line 122 def current_pool(pool) sync { current_stats[pool] } end |
#parser(r) ⇒ Object (protected)
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 173 174 |
# File 'lib/libosctl/zfs/iostat.rb', line 146 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 end |
#remove_pool(pool) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/libosctl/zfs/iostat.rb', line 84 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
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/libosctl/zfs/iostat.rb', line 42 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
55 56 57 |
# File 'lib/libosctl/zfs/iostat.rb', line 55 def started? !reader.nil? end |
#stop ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/libosctl/zfs/iostat.rb', line 59 def stop if iostat_pid Process.kill('TERM', iostat_pid) Process.wait(iostat_pid) @iostat_pid = nil end if reader reader.join @reader = nil end end |
#sync ⇒ Object (protected)
176 177 178 |
# File 'lib/libosctl/zfs/iostat.rb', line 176 def sync mutex.synchronize { yield } end |