class SensuPluginsZFS::ZPool

Attributes

capacity[R]
name[R]
state[R]
vdevs[R]

Public Class Methods

new(name) click to toggle source
# File lib/sensu-plugins-zfs/zpool.rb, line 17
def initialize(name)
  @name = name
  @state = `sudo zpool status #{name} | grep '^ state: ' | cut -d ' ' -f 3`.strip
  @capacity = `sudo zpool get -H capacity #{@name} | awk '{print $3}' | cut -d '%' -f1`.strip.to_i
  @vdevs = create_vdevs name
end

Public Instance Methods

ok?() click to toggle source
# File lib/sensu-plugins-zfs/zpool.rb, line 24
def ok?
  @state == 'ONLINE'
end
scrubbed_at() click to toggle source
# File lib/sensu-plugins-zfs/zpool.rb, line 28
def scrubbed_at
  return Time.at(0) if never_scrubbed?
  return Time.now if scrub_in_progress?

  Time.parse `sudo zpool status #{@name} | grep '^  scan: scrub' | awk '{print $11" "$12" "$13" "$14" "$15}'`.strip # rubocop:disable
end

Private Instance Methods

create_vdevs(name) click to toggle source
# File lib/sensu-plugins-zfs/zpool.rb, line 37
def create_vdevs(name)
  cmd_out = `sudo zpool status #{name} | grep ONLINE | grep -v state | awk '{print $1 " " $2 " " $3 " " $4 " " $5}'`
  cmd_out.lines.map do |l|
    arr = l.strip.split(' ')
    VDev.new(self, arr[0], arr[1], arr[2].to_i, arr[3].to_i, arr[4].to_i)
  end
end
never_scrubbed?() click to toggle source
# File lib/sensu-plugins-zfs/zpool.rb, line 45
def never_scrubbed?
  `sudo zpool status #{@name} | egrep -c "none requested"`.strip.to_i == 1
end
scrub_in_progress?() click to toggle source
# File lib/sensu-plugins-zfs/zpool.rb, line 49
def scrub_in_progress?
  `sudo zpool status #{@name} | egrep -c "scrub in progress|resilver"`.strip.to_i == 1
end