Class: OsCtl::Lib::Zfs::ZpoolTransactionGroups
- Inherits:
-
Object
- Object
- OsCtl::Lib::Zfs::ZpoolTransactionGroups
- Defined in:
- lib/libosctl/zfs/zpool_transaction_groups.rb
Overview
Read interface to /proc/spl/kstat/zfs/<pool>/txgs
Defined Under Namespace
Classes: TransactionGroup, TransactionGroupList
Constant Summary collapse
- PROC_PATH =
'/proc/spl/kstat/zfs'.freeze
- STATES =
{ 'B' => :birth, 'O' => :open, 'Q' => :quiesced, 'W' => :wait_for_sync, 'S' => :synced, 'C' => :committed, '?' => :unknown }.freeze
Instance Attribute Summary collapse
Instance Method Summary collapse
- #each {|pool, transaction| ... } ⇒ Object
-
#initialize(pools: []) ⇒ ZpoolTransactionGroups
constructor
A new instance of ZpoolTransactionGroups.
- #list_pools ⇒ Object protected
- #read_file(pool, txgs_path, uptime) ⇒ Object protected
- #read_paths(txgs_paths) ⇒ Object protected
- #txgs_path(pool) ⇒ Object protected
Constructor Details
#initialize(pools: []) ⇒ ZpoolTransactionGroups
Returns a new instance of ZpoolTransactionGroups.
142 143 144 145 146 147 |
# File 'lib/libosctl/zfs/zpool_transaction_groups.rb', line 142 def initialize(pools: []) read_pools = pools.empty? ? list_pools : pools paths = read_pools.to_h { |pool| [pool, txgs_path(pool)] } @pools = read_paths(paths) end |
Instance Attribute Details
#pools ⇒ Hash<String, TransactionGroupList> (readonly)
139 140 141 |
# File 'lib/libosctl/zfs/zpool_transaction_groups.rb', line 139 def pools @pools end |
Instance Method Details
#each {|pool, transaction| ... } ⇒ Object
151 152 153 |
# File 'lib/libosctl/zfs/zpool_transaction_groups.rb', line 151 def each(&) @pools.each(&) end |
#list_pools ⇒ Object (protected)
202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/libosctl/zfs/zpool_transaction_groups.rb', line 202 def list_pools ret = [] Dir.entries(PROC_PATH).each do |f| next if %w[. ..].include?(f) next unless Dir.exist?(File.join(PROC_PATH, f)) ret << f end ret end |
#read_file(pool, txgs_path, uptime) ⇒ Object (protected)
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/libosctl/zfs/zpool_transaction_groups.rb', line 168 def read_file(pool, txgs_path, uptime) ret = TransactionGroupList.new File.open(txgs_path) do |f| it = f.each_line it.next # skip the header it.each do |line| values = line.strip.split birth_ns = values[1].to_i birth_time = uptime.booted_at + (birth_ns / 1_000_000_000.to_f) ret << TransactionGroup.new( pool:, txg: values[0].to_i, birth_time:, birth_ns:, state: STATES[values[2]], ndirty: values[3].to_i, nread: values[4].to_i, nwritten: values[5].to_i, reads: values[6].to_i, writes: values[7].to_i, otime_ns: values[8].to_i, qtime_ns: values[9].to_i, wtime_ns: values[10].to_i, stime_ns: values[11].to_i ) end end ret end |
#read_paths(txgs_paths) ⇒ Object (protected)
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/libosctl/zfs/zpool_transaction_groups.rb', line 157 def read_paths(txgs_paths) ret = {} uptime = Uptime.new txgs_paths.each do |pool, txgs_path| ret[pool] = read_file(pool, txgs_path, uptime) end ret end |
#txgs_path(pool) ⇒ Object (protected)
215 216 217 |
# File 'lib/libosctl/zfs/zpool_transaction_groups.rb', line 215 def txgs_path(pool) File.join(PROC_PATH, pool, 'txgs') end |