Class: OsCtl::Lib::Zfs::ZpoolTransactionGroups

Inherits:
Object
  • Object
show all
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'
STATES =
{
  'B' => :birth,
  'O' => :open,
  'Q' => :quiesced,
  'W' => :wait_for_sync,
  'S' => :synced,
  'C' => :committed,
  '?' => :unknown,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pools: []) ⇒ ZpoolTransactionGroups

Returns a new instance of ZpoolTransactionGroups.

Parameters:

  • pools (Array<String>) (defaults to: [])


141
142
143
144
145
146
# File 'lib/libosctl/zfs/zpool_transaction_groups.rb', line 141

def initialize(pools: [])
  read_pools = pools.empty? ? list_pools : pools
  paths = Hash[read_pools.map { |pool| [pool, txgs_path(pool)] }]

  @pools = read_paths(paths)
end

Instance Attribute Details

#poolsHash<String, TransactionGroupList> (readonly)

Returns:



138
139
140
# File 'lib/libosctl/zfs/zpool_transaction_groups.rb', line 138

def pools
  @pools
end

Instance Method Details

#each {|pool, transaction| ... } ⇒ Object

Yield Parameters:



150
151
152
# File 'lib/libosctl/zfs/zpool_transaction_groups.rb', line 150

def each(&block)
  @pools.each(&block)
end

#list_poolsObject (protected)



200
201
202
203
204
205
206
207
208
209
210
# File 'lib/libosctl/zfs/zpool_transaction_groups.rb', line 200

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)



166
167
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
# File 'lib/libosctl/zfs/zpool_transaction_groups.rb', line 166

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: pool,
        txg: values[0].to_i,
        birth_time: birth_time,
        birth_ns: 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)



155
156
157
158
159
160
161
162
163
164
# File 'lib/libosctl/zfs/zpool_transaction_groups.rb', line 155

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)



212
213
214
# File 'lib/libosctl/zfs/zpool_transaction_groups.rb', line 212

def txgs_path(pool)
  File.join(PROC_PATH, pool, 'txgs')
end