Class: Riemann::Tools::Md

Inherits:
Object
  • Object
show all
Includes:
Riemann::Tools
Defined in:
lib/riemann/tools/md.rb

Constant Summary

Constants included from Riemann::Tools

VERSION

Instance Attribute Summary

Attributes included from Riemann::Tools

#argv

Instance Method Summary collapse

Methods included from Riemann::Tools

#attributes, #endpoint_name, included, #initialize, #options, #report, #riemann, #run

Instance Method Details

#mdstat_parserObject



14
15
16
# File 'lib/riemann/tools/md.rb', line 14

def mdstat_parser
  @mdstat_parser ||= MdstatParser.new
end

#report_device?(device) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
# File 'lib/riemann/tools/md.rb', line 45

def report_device?(device)
  if !opts[:devices].empty?
    opts[:devices].include?(device)
  else
    !opts[:ignore_devices].include?(device)
  end
end

#tickObject



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
# File 'lib/riemann/tools/md.rb', line 18

def tick
  status = File.read('/proc/mdstat')
  res = mdstat_parser.parse(status)

  res.each do |device, member_status|
    next unless report_device?(device)

    report(
      service: "mdstat #{device}",
      description: member_status,
      state: member_status =~ /\AU+\z/ ? 'ok' : 'critical',
    )
  end
rescue Racc::ParseError => e
  report(
    service: 'mdstat',
    description: "Error parsing mdstat: #{e.message}",
    state: 'critical',
  )
rescue Errno::ENOENT => e
  report(
    service: 'mdstat',
    description: e.message,
    state: 'critical',
  )
end