Class: OsCtl::Lib::Zfs::ObjsetStats::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/libosctl/zfs/objset_stats/parser.rb

Instance Method Summary collapse

Instance Method Details

#parse_objset(path) ⇒ Object (protected)



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/libosctl/zfs/objset_stats/parser.rb', line 18

def parse_objset(path)
  objset = Zfs::ObjsetStats::Objset.new

  File.open(path) do |f|
    # Skip the first two lines
    f.readline
    f.readline

    # Parse the rest
    f.each_line do |line|
      name, type, data = line.strip.split

      case name
      when 'dataset_name'
        objset.dataset_name = data
      when 'writes'
        objset.write_ios = data.to_i
      when 'nwritten'
        objset.write_bytes = data.to_i
      when 'reads'
        objset.read_ios = data.to_i
      when 'nread'
        objset.read_bytes = data.to_i
      end
    end
  end

  objset.dataset_name ? objset : nil
end

#read(pool) ⇒ Zfs::ObjsetStats::PoolTree

Parameters:

  • pool (String)

Returns:



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/libosctl/zfs/objset_stats/parser.rb', line 5

def read(pool)
  tree = Zfs::ObjsetStats::PoolTree.new(pool)

  Dir.glob(File.join('/proc/spl/kstat/zfs', pool, 'objset-*')).each do |f|
    objset = parse_objset(f)
    tree << objset if objset
  end

  tree.build
  tree
end