Class: OsCtl::Cli::Top::ArcStats

Inherits:
Object
  • Object
show all
Defined in:
lib/osctl/cli/top/arcstats.rb

Instance Method Summary collapse

Constructor Details

#initialize(file = '/proc/spl/kstat/zfs/arcstats') ⇒ ArcStats

Returns a new instance of ArcStats.



3
4
5
# File 'lib/osctl/cli/top/arcstats.rb', line 3

def initialize(file = '/proc/spl/kstat/zfs/arcstats')
  parse(file)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/osctl/cli/top/arcstats.rb', line 29

def method_missing(name, *args, **)
  if @data.has_key?(name) && args.size <= 1
    return @data[name] - args[0].send(name) if args[0]

    return @data[name]
  end

  super
end

Instance Method Details

#hit_rate(since = nil) ⇒ Object

Parameters:

  • since (ArcStats, nil) (defaults to: nil)


8
9
10
11
12
13
14
15
16
# File 'lib/osctl/cli/top/arcstats.rb', line 8

def hit_rate(since = nil)
  hits = since ? @data[:hits] - since.hits : @data[:hits]
  misses = since ? @data[:misses] - since.misses : @data[:misses]

  sum = hits + misses
  return 0.0 if sum == 0

  hits.to_f / sum * 100
end

#l2_hit_rate(since = nil) ⇒ Object

Parameters:

  • since (ArcStats, nil) (defaults to: nil)


19
20
21
22
23
24
25
26
27
# File 'lib/osctl/cli/top/arcstats.rb', line 19

def l2_hit_rate(since = nil)
  hits = since ? @data[:l2_hits] - since.l2_hits : @data[:l2_hits]
  misses = since ? @data[:l2_misses] - since.l2_misses : @data[:l2_misses]

  sum = hits + misses
  return 0.0 if sum == 0

  hits.to_f / sum * 100
end

#parse(file) ⇒ Object (protected)



49
50
51
52
53
54
55
56
57
# File 'lib/osctl/cli/top/arcstats.rb', line 49

def parse(file)
  @data = {}

  File.readlines(file)[2..].each do |line|
    name, type, value = line.split

    @data[name.to_sym] = value.to_i
  end
end

#respond_to_missing?(name, *args) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'lib/osctl/cli/top/arcstats.rb', line 39

def respond_to_missing?(name, *args, **)
  if @data.has_key?(name) && args.size <= 1
    true
  else
    super
  end
end